-3

I am looking for a regular expression to search for a portion of a string and then extract a subsequent parameter...

Source strings here:

5288470F7E7155F1A19D7236F837D3CC:120//
5288470F7E7155F1A19D7236F837D3DD:20//
5288470F7E7155F1A19D72DAFF:9302//

The source string could be any length and always follow the same pattern: ID:result//

I need to be able to search the string for the longer ID and then extract the subsequent number between the : and the // pattern. So give this as a search string "5288470F7E7155F1A19D7236F837D3DD" - I need to get the result "20"

Can anyone help?

Thanks

3
  • [a-zA-Z0-9]+:[0-9]+//
    – Matthieu
    Jun 19, 2015 at 12:46
  • :([0-9]+) regex101.com/r/rK3jM2/1
    – ʰᵈˑ
    Jun 19, 2015 at 12:47
  • What language? In PHP something like '~//' . preg_quote($target) . ':(\d+)~'
    – chris85
    Jun 19, 2015 at 12:53

1 Answer 1

0

Using grep you can do it in following way:

grep -Po "(?<=$target_string:)\d+(?=\/\/)"

This will print only the number that you require. The regex used is Perl Compatible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.