Sublime Forum

Regex line regex search (replacement)

#1

given an obfuscated file like

...
  <A>
    <name>ns1</name>
    <ORIGIN>example.com</ORIGIN>
    <class>IN</class>
    <host>127.0.0.1</host>
    <ttl>172800</ttl>
  </A>
  <A>
    <name>ns2</name>
    <ORIGIN>example.com</ORIGIN>
    <class>IN</class>
    <host>127.0.0.2</host>
    <ttl>172800</ttl>
  </A>
  <NS>
    <name>example</name>
    <ORIGIN>com</ORIGIN>
    <class>IN</class>
    <host>ns.example.COM</host>
    <ttl>172800</ttl>
  </NS>
...

I am trying to use the following regex in Sublime Text 4 on a Silicone Mac to get the A records and leave the NS record alone

(?s)\<A\>.*?\<\/A\> does not work.

When plugging same into https://regex101.com/r/LHWvhy/1 it correctly finds the two A records.

What am I doing wrong?

0 Likes

#2

I am not an expert in regex, but the . matches any character excluding newlines. To capture any character including newlines, you may use [\s\S]. So, give it a try using <A>[\s\S]*?</A>.

0 Likes

#3

That worked.

Thanks

0 Likes