Home > front end >  What regex expression would match an apostrophe in front, but not one in between characters?
What regex expression would match an apostrophe in front, but not one in between characters?

Time:11-10

For example, if I have:

'don't

The regex expression would match with the first apostrophe, but not the second. I want to be able to remove the first apostrophe so that in the end, it would simply be the word "don't".

I have tried ^' since ^ is the beginning of a string, but it doesn't seem to work.

Any advice is appreciated!

CodePudding user response:

You have to escape the apostrophe by using "\" but your approach was correct because, as you can see in enter image description here

So you have to use: ^\'

Still, for testing such things, the page I have shared with you with the example works very well for testing. And regex101

regex101 demo

  • Related