1

So ive been trying to match in regex(editpadpro) and i want to match POLYLINE,TYPE=0x6,RoadID ONLY, editpadpro flavor = Perl, Java, .NET any help is appreciated

[POLYLINE] Type=0x6 Label=Lorong Karyawan 18 EndLevel=1 CountryName=MALAYSIA~[0x1d]MYS RegionName=PAHANG~[0x1d]PHG CityName=KUANTAN Zip=25150 RoadID=1154 RouteParam=2,1,0,0,0,0,0,0,0,0,0,0 Data0=(3.77022,103.27289),(3.76988,103.27201) Nod1=0,283024,0 Nod2=1,282992,0 Numbers1=0,O,55,41,N,-1,-1 [END] 

so far ive used this \[POLYLINE]\W+(?:\w+\W+0x6) that match both polyline and Type=0x6

9
  • so far ive used this [POLYLINE]\W+(?:\w+\W+0x6) that match both polyline and Type=0x6 Commented Aug 30, 2020 at 9:18
  • Just searched on multiline on regex101.com ,,, /m is the flag for multi-line Commented Aug 30, 2020 at 9:24
  • yea but apart from this [POLYLINE]\W+(?:\w+\W+0x6) im currently stuck :( just need to find RoadID Commented Aug 30, 2020 at 9:27
  • RoadID=(\d+)/gm - Does that work for you? regex101.com/r/hMV28O/1 Commented Aug 30, 2020 at 9:31
  • Type and RoadID should come after [POLYLINE] in that order? Type is always before RoadID and they can occur in different positions between the other values? See regex101.com/r/r4sn2c/1 using 3 capturing groups Commented Aug 30, 2020 at 9:32

1 Answer 1

1

You could use 3 capturing groups starting by capturing [POLYLINE].

For the other 2 capturing groups, you can match all the lines that do not start with Type or RoadID, and then capture the line that does using a negative lookahead.

(\[POLYLINE\])(?:\r?\n(?!Type).*)*\r?\n(Type=.+)(?:\r?\n(?!RoadID).*)*\r?\n(RoadID=.+) 

See a Regex demo

Explanation

  • (\[POLYLINE\]) Group 1 match [POLYLINE]
  • (?:\r?\n(?!Type).*)*\r?\n Repeatedly match all lines that do not start with Type
  • (Type=.+) Group 2 Match Type= followed by 1+ times any char
  • (?:\r?\n(?!RoadID).*)*\r?\n Repeatedly match all lines that do not start with RoadID
  • (RoadID=.+) Group 3 match RoadID= followed by 1+ times any char
Sign up to request clarification or add additional context in comments.

4 Comments

hey thanks again, and i want to ask you if i want to match Type thats only Type=0x6
You could specify it in the pattern instead of the .+ like (\[POLYLINE\])(?:\r?\n(?!Type).*)*\r?\n(Type=0x6)(?:\r?\n(?!RoadID).*)*\r?\n(RoadID=.+) regex101.com/r/kgZvcM/1
hey thanks man appreciate it, sorry to bother you again but ive a question, i want to replace(or add) for example roadBlabla=1,0,0,0 under RoadID
@JohnWeck If you want to keep all the current groups, you can put the matches between also in a group and use the 5 capturing groups in the replacement followed by a newline and the text that you want to add regex101.com/r/wM06qQ/1 Or if you only want to add the value, you don't need any group but you can just use the full match in the replacement instead followed by the text that you want to add regex101.com/r/CEJmQR/1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.