Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 3, 2006, 04:23 PM   #1
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
grep, regular expressions, HTML files

I could use a little help here. Alright, let's say I have this here HTML file, and I want to extract some of the things in brackets (which are just placeholders - in the HTML files I'm actually extracting data from there will be actual content where the brackets are) using grep, then send that data to a file.

I'm not entirely sure which regular expressions to use. Also, for a given piece of data I don't want the regular expression to return more than one match.

Oh, ignore all the broken links and images in the linked-to HTML file - they're supposed to be broken.
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Aug 3, 2006, 07:49 PM   #2
savar
macrumors 68000
 
savar's Avatar
 
Join Date: Jun 2003
Location: District of Columbia
Send a message via AIM to savar
Quote:
Originally Posted by wrldwzrd89
I could use a little help here. Alright, let's say I have this here HTML file, and I want to extract some of the things in brackets (which are just placeholders - in the HTML files I'm actually extracting data from there will be actual content where the brackets are) using grep, then send that data to a file.

I'm not entirely sure which regular expressions to use. Also, for a given piece of data I don't want the regular expression to return more than one match.

Oh, ignore all the broken links and images in the linked-to HTML file - they're supposed to be broken.
First off, the best regex tutorial I've ever read:
http://www.regular-expressions.info/tutorial.html

What you're looking for is something like this:
\[.*?\]

This matches a pair of square brackets with or without stuff in the middle. The ? makes * ungreedy -- it will return the shortest match possible. The brackets I think must be escaped since they have special meaning in a regex.
__________________
Mehce
savar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Regular Expression problem grabbing data from html page petersz98 iPhone/iPad Programming 4 Jul 9, 2009 05:25 AM
Regular Expressions - Help stuppy Mac Programming 2 Nov 11, 2008 01:47 PM
What app will let me edit a .html file in HTML? LoneWolf121188 OS X 12 Aug 28, 2008 04:36 PM
Anyone good with Regular Expressions? Particularly PHP's preg_match()? radiantm3 Web Design and Development 10 Jun 24, 2008 08:07 PM
Help with regular expressions simX OS X 3 Jul 2, 2006 05:59 PM


All times are GMT -5. The time now is 05:53 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC