Skip to main content
The 2024 Developer Survey results are live! See the results

I need to match all of these opening tags:

<p>
<a href="foo">

But not theseself-closing tags:

<br />
<hr class="foo" />

I came up with this and wanted to make sure I've got it right. I am only capturing the a-z.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except /, then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

I need to match all of these opening tags:

<p>
<a href="foo">

But not these:

<br />
<hr class="foo" />

I came up with this and wanted to make sure I've got it right. I am only capturing the a-z.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except /, then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

I need to match all of these opening tags:

<p>
<a href="foo">

But not self-closing tags:

<br />
<hr class="foo" />

I came up with this and wanted to make sure I've got it right. I am only capturing the a-z.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except /, then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

Notice removed Reward existing answer by Cole Tobin
Bounty Ended with NealB's answer chosen by Cole Tobin
Notice added Reward existing answer by Cole Tobin
Bounty Started worth 100 reputation by Cole Tobin
Notice removed Canonical answer required by Cole Tobin
Bounty Ended with Jonathan Wood's answer chosen by Cole Tobin
Notice added Canonical answer required by Cole Tobin
Bounty Started worth 50 reputation by Cole Tobin
Notice removed Reward existing answer by Dharman
Notice added Reward existing answer by justANewb stands with Ukraine
Post Locked by Robert Harvey
Notice added Comments only by Robert Harvey
Notice removed Historical significance by Robert Harvey
Post Unlocked by Robert Harvey
Notice added Historical significance by Robert Harvey
Post Locked by Robert Harvey
Notice removed Reward existing answer by ThiefMaster
Bounty Ended with Kaitlin Duck Sherwood's answer chosen by ThiefMaster
edited tags
Link
richarbernal
  • 1.1k
  • 2
  • 14
  • 32
Notice added Reward existing answer by ThiefMaster
Bounty Started worth 50 reputation by ThiefMaster
Rollback to Revision 9
Source Link
Alan Moore
  • 74.7k
  • 13
  • 106
  • 158

I need to match all of these opening tags:

<p>
<a href="foo">

But not these:

<br />
<hr class="foo" />

I came up with this and wanted to make sure I've got it right. I am only capturing the 'a-z'a-z.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except /, then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

I need to match all of these opening tags:

<p>
<a href="foo">

But not these:

<br/>
<hr class="foo"/>

I came up with this and wanted to make sure I've got it right. I am only capturing the 'a-z'.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except / then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

I need to match all of these opening tags:

<p>
<a href="foo">

But not these:

<br />
<hr class="foo" />

I came up with this and wanted to make sure I've got it right. I am only capturing the a-z.

<([a-z]+) *[^/]*?>

I believe it says:

  • Find a less-than, then
  • Find (and capture) a-z one or more times, then
  • Find zero or more spaces, then
  • Find any character zero or more times, greedy, except /, then
  • Find a greater-than

Do I have that right? And more importantly, what do you think?

improved formatting
Source Link
Loading
Notice removed Draw attention by casperOne