1

I wan to extract the string from the below line of code

span id="testing" This is testing span a id="test" link a

from the above code I want to extract the id's alone using regex

eg: "testing", "test"

3
  • 1
    regex could simply be something like "(\w+)" if your identifiers are comprised only of "word characters" (letters, underscore) Commented Feb 24, 2021 at 8:48
  • I want to extract only the string between id=" " Commented Feb 24, 2021 at 8:51
  • No I mean I want to get string between id=" " Commented Feb 24, 2021 at 8:51

2 Answers 2

1

If your identifiers are comprised of word characters only:

this regex works: (?<=id=")\w+(?="). The full match is the id. However, this could cause compatibility issue in Safari, that doesn't support lookbehinds ((?<= ))

Test it on Regex101

You can also use capture groups with id="(\w+)". The only captured group will be the id you're looking for.

Test it on Regex101

Sign up to request clarification or add additional context in comments.

1 Comment

FYI. It's better to use capture groups since safari doesn't support lookbehinds.
1

You can use id="(\w+)" as the regex.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.