2

Trying to get the all characters until new line after one/more digits with positive lookbehind from below text with this

(?<=below customer.\s.*\n.* )(.*)
I order standardinstalation to below customer.
Paul Rilley
Abbeyroad 55

It works (gives 55) if the roadname does not have a space. Not working with (High Tory road). Also there could be letters after the digits (55b) that I should get. I need to look behind the words (below customer) since the first line is the only part that is always the same.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
HenkkaHH
  • 21
  • 1
  • 1
    Maybe [`(?s)below customer.*?(\d+[a-zA-Z]*)`](http://regexstorm.net/tester?p=%28%3fs%29below+customer.*%3f%28%5cd%2b%5ba-zA-Z%5d*%29&i=I+order+standardinstalation+to+below+customer.%0d%0aPaul+Rilley%0d%0aAbbeyroad+55b%0d%0a) could potentially work? – JvdV Sep 03 '21 at 14:01
  • It would help to come up with a better suggestion if you posted the regex pipeline part. Are you accessing the regex match value or do you define a group? – Wiktor Stribiżew Sep 04 '21 at 10:51

2 Answers2

1

You can use

(?m)(?<=below customer\.\r?\n(?:.+\n)*?.+ )(\d+[A-Za-z]*)\r?$

See the .NET regex demo.

Details:

  • (?m) - multiline mode to make $ match end of any line is on
  • (?<=below customer\.\r?\n(?:.+\n)*?.+ ) - the lookbehind to match below customer., then a line ending sequence, then zero or more lines with a line ending sequence, as few as possible, and then zero or more chars other than newline till the last space followed with
  • (\d+[A-Za-z]*) - Group 1: one or more digits and then zero or more letters
  • \r?$ - an optional CR char and the end of line.

It will also match 55b.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Hhmm...this seems to be ok right? Don't know if you need the capture group but ok – The fourth bird Sep 03 '21 at 15:32
  • 1
    @Thefourthbird It depends on what OP has in their pipeline. If they refer to Group 1, we can't remove the brackets. If we knew the bigger picture, we could even try more optimizations. – Wiktor Stribiżew Sep 03 '21 at 15:52
  • I use the expression in RPA matches activity to get the value. Tryed the suggested solution it didnt work. I also should mention that there are more lines with text below Abbeyroad 55. – HenkkaHH Sep 06 '21 at 08:05
  • @HenkkaHH Your current question is about how to match the number that contains below 2 lines of the word if the address contains a space. If you want to say there are more lines, you need to add that in the question, and it would be great to add what you tried to make sure variable line texts are matched. – Wiktor Stribiżew Sep 06 '21 at 08:27
  • @HenkkaHH Try `(?m)(?<=below customer\.\r?\n(?:.+\n)*?.+ )(\d+[A-Za-z]*)\r?$`, see [demo](http://regexstorm.net/tester?p=%28%3fm%29%28%3f%3c%3dbelow+customer%5c.%5cr%3f%5cn%28%3f%3a.%2b%5cn%29*%3f.%2b+%29%28%5cd%2b%5bA-Za-z%5d*%29%5cr%3f%24&i=I+order+standardinstalation+to+below+customer.%0d%0aPaul+Rilley%0d%0asmall+smiley+and+co.%0d%0ablah+blah+-+blargghhhhh%0d%0aAbbey+A.+road+55%0d%0a%0d%0aI+order+standardinstalation+to+below+customer.%0d%0aPaul+Rilley%0d%0aAbbey+road+55b). – Wiktor Stribiżew Sep 06 '21 at 08:27
-1

In most regex flavors, a lookbehind must be fixed width. In .NET, variable width is supported.

You can use both in PCRE and .NET:

/(?<=below customer\.)\r?\n.*\r?\n.* (\w+)$/gm

Demo for PCRE

Demo for .NET

dawg
  • 98,345
  • 23
  • 131
  • 206