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"

Pac0
  • 21,465
  • 8
  • 65
  • 74
Logan
  • 15
  • 4

2 Answers2

1

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

zmbq
  • 38,013
  • 14
  • 101
  • 171
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

Pac0
  • 21,465
  • 8
  • 65
  • 74