Reputation: 21
I would like to get the text from (character/s) to another (character/s), excluding the searching characters (meaning whatever in between the two searching terms but not including them)
For example this text
href="https://old.reddit.com/user/TKayOKAY"> class="author"
using the regex /user/(.*?)"/g returned "user/TKayOKAY""
How to remove user/
and "
the end double quotes, to get only the username?
basically returning >> TKayOKAY for example.
Upvotes: 0
Views: 27
Reputation: 1
I would decide it so
/user/([A-z]+)
I have excluded "common" expressions like ". *", In order to avoid subtle problems. If you see that the string contains only letters, then look for only letters.
Upvotes: 0
Reputation: 18357
If your regex dialect supports lookarounds, you can use lookarounds based regex so your full match is the only intend text.
(?<=/user/)(.*?)(?=")
OR you can capture your data from group1 using your own regex mentioned in your post.
/user/(.*?)"
This demo will show your intended text capture in present in group1
Upvotes: 1