0

I have a text file in which is present the string

orderId=123456

The string can change but the format should always be orderId=six numbers.

I would like to extract the six numbers I tryied with the following code

orderId=[0-9]{6}

but i do not know how to remove orderId= could you please help?


UPDATE

Below an example of a string

"display:none;" name="LanguageSelectionForm" action="http://pippo.com/webapp/wcs/stores/servlet/CabinSelectionView?packageType=onlyCruise&recommendedMaskCommission=false&catalogId=10001&catEntryId=360579&orderId=351026&storeId=10251" method="post" id="LanguageSelectionForm">

i'm using Jmeter and this response comes from http response

user3299274
  • 57
  • 1
  • 10
  • 2
    What language are you using? – zx81 May 30 '14 at 09:08
  • will "orderId=" be constant. Can you also paste the sample data – Devesh May 30 '14 at 09:09
  • @user3299274 Did one of the answers help with the problem, or are you still wrestling with it? If an answer solves your problem, please consider "accepting it" by clicking the checkmark on the left, as this is how the reputation system works (accepting an anwer gives reputation to both the answerer and to you). Of course there is no obligation to do so. As you know, you can also upvotes any answer that is helpful. Thanks for listening to my 20-second SO rep tutorial. :) – zx81 May 30 '14 at 22:53
  • Thank you your solution Saved My workday – user3299274 May 30 '14 at 23:57

3 Answers3

6

There are several options.

Perl, PHP, Ruby 2

Using \K with this short regex,

orderId=\K\d{6}

only the six digits will be matched.

Flavors that support lookbehind

(?<=orderId=)\d{6}

Again, only the six digits will be matched.

Other flavors

orderId=(\d{6})

Here, the whole string is captured, and the six digits are captured in Group 1, which can be examined in your language.

How the regexes work

orderId=\K\d{6}

  • Match the character string “orderId=” literally (case sensitive) orderId=
  • Keep the text matched so far out of the overall regex match \K
  • Match a single character that is a “digit” (0–9 in any Unicode script) \d{6}
    • Exactly 6 times {6}

(?<=orderId=)\d{6}

  • Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) (?<=orderId=)
    • Match the character string “orderId=” literally (case sensitive) orderId=
  • Match a single character that is a “digit” (0–9 in any Unicode script) \d{6}
    • Exactly 6 times {6}

orderId=(\d{6})

  • Match the character string “orderId=” literally (case sensitive) orderId=
  • Match the regex below and capture its match into backreference number 1 (\d{6})
    • Match a single character that is a “digit” (0–9 in any Unicode script) \d{6}
      • Exactly 6 times {6}
zx81
  • 41,100
  • 9
  • 89
  • 105
1

An expression like this will return, in group 1 the digits you require provided the input is in the form anyText=123456

[a-zA-Z]+=(\d{6})

If the string at the start doesn't change, then simply do this:

orderId=(\d{6})
DavidG
  • 113,891
  • 12
  • 217
  • 223
0

Using Regex Extractor in Jmeter for below mentioned string:

"display:none;" name="LanguageSelectionForm" action="http://pippo.com/webapp/wcs/stores/servlet/CabinSelectionView?packageType=onlyCruise&amp;recommendedMaskCommission=false&amp;catalogId=10001&amp;catEntryId=360579&amp;orderId=351026&amp;storeId=10251&quot; method="post" id="LanguageSelectionForm">

Regular Expression (to extract orderId): ".orderId=(.+?)&."

link for Reference:http://www.tutorialspoint.com/jmeter/jmeter_regular_expressions.htm

Hope this will help.

Zubair M Hamdani
  • 1,693
  • 1
  • 13
  • 14