-1

Here is my regular expression. <form[\s][\s\S]*action="[\s\S]*?". And below is the whole content string.

<form role="search" method="get" name="search" action="/job/ice-cream-release/search/" abc d ="" </form>abcd <parameters:<form method="post" autocomplete="off" name="parameters" action="build?delay=0sec"><div width="100%" class="parameters"><tbody>

I have already used *? in the regular expression, and I assume the return result should be below, which is the minimize result.

<form role="search" method="get" name="search" action="/job/ice-cream-release/search/"

But the the actual result is

<form role="search" method="get" name="search" action="/job/ice-cream-release/search/" abc d ="" </form>abcd <parameters:<form method="post" autocomplete="off" name="parameters" action="build?delay=0sec"

How does this happen? Thanks.

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Robin Sun
  • 1,045
  • 3
  • 15
  • 31

1 Answers1

1

You have two action character sequences within your input string.
That's why the first * expands past the first action. (Up to the second and last action)

Make that one non-greedy as well, by adding a ?, to get the desired result:

<form[\s][\s\S]*?action="[\s\S]*?"

Jay
  • 2,532
  • 10
  • 16