views:

573

answers:

3

I need to separate out a bunch of image urls from a document in which the images are associated with names like this:

bellpepper = "http://images.com/bellpepper.jpg"
cabbage = "http://images.com/cabbage.jpg"
lettuce = "http://images.com/lettuce.jpg"
pumpkin = "http://images.com/pumpkin.jpg"

I want to remove all text except the URLs from the file by deleting the variable name, equals sign and double quotes so I have a new file that is just a list of URLs, one per line.

I've tried various ways of identifying the non-URL data using regular expressions in Textpad by checking the "Regular expression" checkbox in the Find dialog window but Textpad doesn't seem to like any of them.

Under

Configure->Preferences->Editor

there's an option:

"Use POSIX regular expression syntax"

As opposed to what?

Is it possible that my problems performing this regex operation have to do with some quirk of Textpad's implementation of regex?

+1  A: 

Besides POSIX there are also Perl style regular expressions.

R. Kettelerij
i dont think you can use Perl style regex in TextPad
akf
+2  A: 

The POSIX alternative is as opposed to the TextPad default. From the Search/Replace help doc:

TextPad's regular expressions are based on POSIX standard P1003.2, but the syntax can be that of POSIX, or UNIX extended regular expressions (the default).

to get the job done in TextPad, use the following:

Find in: ^[^"]*"\([^"]*\)"
Replace with: \1

edit:

to break the expression down:

^ - start of line
[^"]* - in a set the caret ^ is for negation, 
        so a greedy match of anything that is not a "
        in this case, everything up to the first quote
" - the first quote per line in your source text
\(...\) - puts together a group that can be referenced later
[^"]* - same explanation as above, this time matching the url in question
" - the last quote on the line

Also, looking through the help doc on Regex in TextPad, there is a chart of legal expressions listing both the 'Default' and the 'POSIX' versions side by side. The only difference seems to be the escaping of the Grouping parens () and the Occurance curlies {} in the Default and the lack of escaping in the POSIX version.

With that in mind, to get the job done in TextPad with the 'use POSIX regular expression syntax' option checked, swap out the above 'Find in' expression with the following:

Find in: ^[^"]*"([^"]*)"
akf
That's so cool. It didn't work with the POSIX option turned on but it did work when I turned it off. Awesome. Thanks. Wish I understood what you did there.
boysenberry
@boysenberry, i have updated my response with some detail.
akf
This is amazing. Thanks so much for explaining. Excellent explanation!
boysenberry
A: 

The original basic regular expressions, such as may be found on "sed", have some differences to what we most often use. For example, you use \( and \) to indicate groups, instead of ( and ), and there is no "+" modifier.

Also, I note on the linked question that your "*" is outside the parenthesis instead of inside. That means only one char will be matched on the first group.

Daniel