01-14-2009, 07:52 PM | #1 |
Addict
Posts: 210
Karma: 4282
Join Date: Oct 2008
Location: Florida
Device: Sony 505, Kindle 3, iPad 3
|
Need help with regex expression
I am trying to use find and replace in MS Word to get rid of footnote references in a text file. The references are in the form [n] or [nn] where n represents a numerical digit.
I presume that the bracket symbols, [] must be protected in the regex lingo because everything I try doesn't work. I have tried both [?] and[*] (wildcards) and they don't work. I would appreciate any help. |
01-14-2009, 08:01 PM | #2 |
Sir Penguin of Edinburgh
Posts: 12,375
Karma: 23555235
Join Date: Apr 2007
Location: DC Metro area
Device: Shake a stick plus 1
|
MSWord uses nonstandard terms for regular expressions.
This one will work: (\[*\]) But I recommend that you use this one: (\[?\]) add more '?' as needed to catch all the desired terms |
Advert | |
|
01-14-2009, 08:42 PM | #3 |
Wizard
Posts: 1,279
Karma: 1002683
Join Date: Nov 2008
Location: New York
Device: PRS-700
|
nate i assume when you use \ in a regex that means to look for the leading character instead of it being used as part of the formatting? if so i think that makes it so it finally makes sense to me.
I find that Notepad++ works great for removing junk lines in the text. in notepad++ go to search > find search for a term that appears in the lines you want to remove. check mark line, hit find all. go to search > delete bookmarked lines |
01-14-2009, 08:46 PM | #4 | |
Sir Penguin of Edinburgh
Posts: 12,375
Karma: 23555235
Join Date: Apr 2007
Location: DC Metro area
Device: Shake a stick plus 1
|
Quote:
The characters [] have a special meaning in regular expressions. A slash '\' is placed before each one to force the use of the non-special meaning. Anyway, I tested the expressions I provided above. They work correctly in MSWord. |
|
01-14-2009, 09:02 PM | #5 |
Wizard
Posts: 1,279
Karma: 1002683
Join Date: Nov 2008
Location: New York
Device: PRS-700
|
|
Advert | |
|
01-14-2009, 09:03 PM | #6 |
Reader
Posts: 11,504
Karma: 8720163
Join Date: May 2007
Location: South Wales, UK
Device: Sony PRS-500, PRS-505, Asus EEEpc 4G
|
It sometimes is worth looking to see whether the footnotes are in a particular style. If so, you can search and delete the instances of the style.
|
01-15-2009, 04:04 AM | #7 |
frumious Bandersnatch
Posts: 7,533
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
In vim it could be: \[\d\+\]
\[, \]: literal [ and ] \d: a digit \+: repeated one or more times. |
01-15-2009, 11:46 AM | #8 |
Addict
Posts: 210
Karma: 4282
Join Date: Oct 2008
Location: Florida
Device: Sony 505, Kindle 3, iPad 3
|
|
01-15-2009, 06:29 PM | #9 |
Wizard
Posts: 2,999
Karma: 300001
Join Date: Jan 2007
Location: Citrus Heights, California
Device: TWO Kindle 2s, one each Bookeen Cybook Gen3, Sony PRS-500, Axim X51V
|
Sooo.... Does anyone understand how to get Word to replace the string 'p. ###', where ### can be anything from 1 to 999, with a space? Without having to do a separate find/replace on 3-digit, then 2-digit, then 1-digit numeric strings?
Derek |
01-15-2009, 06:36 PM | #10 | |
Sir Penguin of Edinburgh
Posts: 12,375
Karma: 23555235
Join Date: Apr 2007
Location: DC Metro area
Device: Shake a stick plus 1
|
Quote:
(p. [0-9]{1,3}) |
|
01-15-2009, 06:42 PM | #11 |
Wizard
Posts: 2,999
Karma: 300001
Join Date: Jan 2007
Location: Citrus Heights, California
Device: TWO Kindle 2s, one each Bookeen Cybook Gen3, Sony PRS-500, Axim X51V
|
Nate,
Thanks! Derek |
01-18-2009, 01:44 PM | #12 |
Addict
Posts: 210
Karma: 4282
Join Date: Oct 2008
Location: Florida
Device: Sony 505, Kindle 3, iPad 3
|
Nate,
You're a wonder at these expressions. Do you have any suggestions for where I might teach myself this stuff? I use primarily Word for my editing. |
01-18-2009, 02:53 PM | #13 | |
book creator
Posts: 9,656
Karma: 3856660
Join Date: Oct 2008
Location: Luxembourg
Device: Kindle Scribe
|
Quote:
Andy's way also works fine and is fast but can lead to errors (overkill) if you're not conscientious. You really have to be sure that there is nothing else on that line you're looking for ever! Last edited by mtravellerh; 01-18-2009 at 02:57 PM. |
|
01-18-2009, 03:27 PM | #14 | |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Quote:
MS Word does not use standard regular notation and in addition it's implementation is inferior to true RegEx. But it is still powerful and conceptually still make use of the regular expression concepts I'd recommend reading http://www.regular-expressions.info/ These two articles are pretty good. They got me started when I decided to write the BookCreator tool http://office.microsoft.com/en-us/he...873041033.aspx http://office.microsoft.com/en-us/he...873051033.aspx Also there are scores of Perl and Javascript tutorials that use regular expressions. The syntax will be a little different but they still try to solve the same problems and you will learn from the exercise of converting the syntax. Reglar expressions have a steep learning curve but once your over the first hump, you'll realize its the best invention since coffee. ... Yea I know the saying is sliced bread but give me coffee and regluar expressions --hmmmm I'm in heaven. =X= |
|
01-19-2009, 04:29 AM | #15 | |
eBook Enthusiast
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
|
Quote:
\[[0-9]*\] is safer in that it will only catch numeric references. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Regular Expression Help | Azhad | Calibre | 86 | 09-27-2011 02:37 PM |
Regular Expression Help | smartmart | Calibre | 5 | 10-17-2010 05:19 AM |
Need Help Creating a Regular Expression | Worm | Calibre | 9 | 08-18-2010 01:20 PM |
Help with the regular expression | Dysonco | Calibre | 9 | 03-22-2010 10:45 PM |
help with regex expression | daesdaemar | Workshop | 4 | 02-19-2010 07:38 AM |