06-18-2015, 12:18 AM | #1 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Problem with a regexp
Hi,
I don't know if this problem goes here, but as I use the regexp for modifying the book comments in the bulk edit metadata, I don't know any other place. My regexp is like this: Code:
<div><p( [^>]*)?> Code:
<div><p class="pp"> and I'm not able to |
06-18-2015, 03:20 PM | #2 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If for some reason you really want to make the "[^>]*" not greedy then you must put the question immediately after the star, as in "[^>]*?" |
|
06-18-2015, 03:43 PM | #3 |
Grand Sorcerer
Posts: 27,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I think she's trying to use the question mark to make the entire group (within the parens) optional.
@Terisa: While your regex should match (it does for me when I use it in other applications), the question mark (as well the space inside the group) is probably not necessary. The * is already 0 or more repetitions, which implies that what precedes it is "optional." When you say "goes wrong," do you mean you want your expression to match the code example you gave, or you don't want it to match? Something like: Code:
<div><p([^>]*)> If you're looking for something else, you'll need to clarify. Last edited by DiapDealer; 06-18-2015 at 03:48 PM. |
06-18-2015, 03:58 PM | #4 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
@diapdealer, thank you, you've understood me although I haven't explained myself Yes, I want the expression to match the example I've given, and yes, I want optional the part after the the <p, so it can be an empty p.
Now, as you and @chaley have shown me the fails in the expression, I understand I should have checked it myself more thoroughly. Thank you very much. |
06-19-2015, 02:57 PM | #5 |
Grand Sorcerer
Posts: 27,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
You're welcome!
Feel free to drop the parens entirely if you don't need to capture the p tag's attributes for any reason. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre problem with 'REPLACE WITH' RegExp | DaveClouding | Editor | 2 | 05-05-2015 12:38 AM |
Need help with RegExp | theichens | Calibre | 1 | 02-09-2013 08:40 AM |
Help with Regexp for importing Magazines | donnelyn | Library Management | 5 | 08-24-2011 10:56 AM |
Regexp help - I think... | paulfiera | Calibre | 4 | 07-20-2011 03:27 AM |
Error in Regexp documentation | arifzaman | Calibre | 3 | 03-02-2011 06:03 AM |