1

I have response body which contains

"<h3 class="panel-title">Welcome 
                                First Last </h3>"

I want to fetch 'First Last' as a output

The regular expression I have tried are

"Welcome(\s*([A-Za-z]+))(\s*([A-Za-z]+))" 
"Welcome \s*([A-Za-z]+)\s*([A-Za-z]+)"

But not able to get the result. If I remove the newline and take it as "<h3 class="panel-title">Welcome First Last </h3>" it is detecting in online regex maker.

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
Shivalika
  • 13
  • 3

5 Answers5

0

Well, usually I don't recommend regex for this kind of work. DOM manipulation plays at its best.

but you can use following regex to yank text:

/(?:<h3.*?>)([^<]+)(?:<\/h3>)/i

See demo at https://regex101.com/r/wA2sZ9/1

This will extract First and Last names including extra spacing. I'm sure you can easily deal with spaces.

Saleem
  • 7,965
  • 2
  • 16
  • 31
0

In jmeter reg exp extractor you can use:

<h3 class="panel-title">Welcome(.*?)</h3>

Then take value using $1$.

In the data you shown welcome is followed by enter.If actually its part of response then you have to use \n.

  <h3 class="panel-title">Welcome\n(.*?)</h3>

Otherwise above one is enough.

First verify this in jmeter using regular expression tester of response body.

Aajan
  • 837
  • 1
  • 8
  • 22
0

Welcome([\s\S]+?)<

Try this, it will definitely work.

Kaushlendra Jha
  • 394
  • 1
  • 11
0

I suspect your problem is the carriage return between "Welcome" and the user name. If you use the "single-line mode" flag (?s) in your regex, it will ignore newlines. Try these:

(?s)Welcome(\s*([A-Za-z]+))(\s*([A-Za-z]+)) 

(?s)Welcome \s*([A-Za-z]+)\s*([A-Za-z]+)

(this works in jMeter and any other java or php based regex, but not in javascript. In the comments on the question you say you're using javascript and also jMeter - if it is a jMeter question, then this will help. if javaScript, try one of the other answers)

andrew lorien
  • 1,464
  • 18
  • 22
-1

Regular expressions are greedy by default, try this

Welcome\s*([A-Za-z]+)\s*([A-Za-z]+)

Groups 1 and 2 contain your data

Check it here

Yomna Fahmy
  • 167
  • 1
  • 6