Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 06-18-2015, 12:18 AM   #1
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
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( [^>]*)?>
The problem is that this search goes wrong if I have something like:

Code:
<div><p class="pp">
Do you see any obvious problem? I've never been very comfortable with regexp.
and I'm not able to
Terisa de morgan is offline   Reply With Quote
Old 06-18-2015, 03:20 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Terisa de morgan View Post
Code:
<div><p( [^>]*)?>
The problem is that this search goes wrong if I have something like:

Code:
<div><p class="pp">
The ? after the parenthesis is being interpreted as a normal character because there isn't a "*" matching expression immediately in front of it (the parenthesis intervenes). I assume you are trying to make the * not greedy. That is not required because the NOT ^ character set is already not greedy, stopping at the first ">".

If for some reason you really want to make the "[^>]*" not greedy then you must put the question immediately after the star, as in "[^>]*?"
chaley is offline   Reply With Quote
Old 06-18-2015, 03:43 PM   #3
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
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([^>]*)>
Should be sufficient to match any p tag that immediately follows a div tag-- regardless if the p tag has any attributes or not.

If you're looking for something else, you'll need to clarify.

Last edited by DiapDealer; 06-18-2015 at 03:48 PM.
DiapDealer is online now   Reply With Quote
Old 06-18-2015, 03:58 PM   #4
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
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.
Terisa de morgan is offline   Reply With Quote
Old 06-19-2015, 02:57 PM   #5
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
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.
DiapDealer is online now   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 02:11 PM.


MobileRead.com is a privately owned, operated and funded community.