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,311
  • 11
  • 25

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
  • 477,764
  • 81
  • 611
  • 541
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
  • 41,294
  • 14
  • 93
  • 121