0

I have this :

<title>Title</title>

All I want to do is express this in regex. I have:

/<[A-Za-z]>\w<\/[A-Za-z]>

Can anyone help

Andrew Briggs
  • 1,329
  • 12
  • 26

2 Answers2

1

You need a + after each of the [] and after the \w to represent "one or more".

/<[A-Za-z]+>\w+<\/[A-Za-z]+>/

But it looks like you're trying to parse HTML with regex. You might want to consider not doing that.

Community
  • 1
  • 1
Amber
  • 507,862
  • 82
  • 626
  • 550
0

You should use a backreference. If you don't then you will match:

<title>blabla</otherTag>

Try this:

/<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>(.*?)</\1>/
Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123