Solved

Need help with Regular Expression

Posted on 2006-11-27
9
500 Views
Last Modified: 2011-04-14
I know next to nothing about RegEx.  I'm using Textpad, which uses RegEx to do search/replace.

I have a large file that I want to condense.  It's a DNS table.

In this case, I want to find all lines that end in 'B&P" )' and replace the entire line with 25spaces followed by TXT ( "B&P" )

Here's a sample.  Can someone help me with this?

183.142.x.x         A      127.0.0.1
                        TXT      ( "damon somers on 2/23/2005 6:26:45 AM B&P" )
                        TXT      ( "dave orines on 2/23/2005 6:26:48 AM B&P" )
                        TXT      ( "franklyn abeyta on 2/23/2005 6:26:43 AM B&P" )
                        TXT      ( "guadalupe strysko on 2/23/2005 6:26:42 AM B&P" )
                        TXT      ( "laurence blackshear on 2/23/2005 6:26:44 AM B&P" )
                        TXT      ( "lyndon plazza on 2/23/2005 6:26:46 AM B&P" )
                        TXT      ( "patrick doell on 2/23/2005 6:26:41 AM B&P" )
                        TXT      ( "rocky liem on 2/23/2005 6:26:43 AM B&P" )
                        TXT      ( "vincent stern on 2/23/2005 6:26:46 AM B&P" )
48.142.x.x          A      127.0.0.1
                        TXT      ( "daniel spooner on 2/2/2005 12:30:40 AM B&P" )
                        TXT      ( "glen schwalenberg on 2/2/2005 12:30:39 AM B&P" )
                        TXT      ( "vito vierra on 2/2/2005 12:30:38 AM B&P" )
                        TXT      ( "ward hope on 2/2/2005 12:30:37 AM B&P" )
                        TXT      ( "branden kriege on 2/2/2005 12:30:36 AM B&P" )
                        TXT      ( "zane duenas on 2/2/2005 12:30:34 AM B&P" )
                        TXT      ( "vincenzo danesh on 2/2/2005 12:30:34 AM B&P" )
                        TXT      ( "leroy bauman on 2/2/2005 12:30:33 AM B&P" )
0
Comment
Question by:nummagumma2
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 18025092
nummagumma2,

I don't know about implementing this in your program but the expression you want is.

.+B&P"\x20\)

It will identify the lines you mentioned.  Most like the replace will require you to type the 25 spaces and then TXT ( "B&P" ).  In other words in the box to specify the text to replace the match with type [25 spaces]TXT ( "B&P" ).  [25 spaces] in the previous sentences is for literally 25 spaces.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 1

Expert Comment

by:achillecarsten
ID: 18025301
The example is the "before", correct?

thus the "AFTER" would be something like

                         TXT ( "B&P" )?
0
 
LVL 1

Expert Comment

by:achillecarsten
ID: 18025408
Whoa, running TextEdit, it's regex is pretty brutal. (Running through wine on linux, at least)
Anyhow, click search/replace, select REGEX
search for -----------><b>^.*B.P</b><------------------
Replace with ---------------><b>             TXT \(\"B\&P</b><----------------- (increase the number of spaces as you wish)


0
 
LVL 1

Expert Comment

by:achillecarsten
ID: 18025415
Hmm, let me try that again
Search for: "^.*B.P"
Replace with: "                         TXT \(\"B\&P"
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 4

Expert Comment

by:Raymun
ID: 18025433
B&P"\)$
0
 
LVL 4

Expert Comment

by:Raymun
ID: 18025437
will look for it at the end of the string; not the first occurrence of it
0
 
LVL 1

Accepted Solution

by:
achillecarsten earned 250 total points
ID: 18025473
Raymum: this editor is strange, not sure what regex version they implement
anyhow, yeah, last occurrence would be:
Search for:^.+B&P"\ ?.$
Replace with:                        TXT \(\"B\&P\"\)
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 18030891
achille - your final one worked with just a few minor tweaks to the spacing.  Thank you!  I'm posting another one with similar issue that I've never been able to figure out.
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 18030917
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now