Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 09-30-2022, 09:21 AM   #1
skil-phil
Connoisseur
skil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animals
 
skil-phil's Avatar
 
Posts: 57
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
Regex question

Hi,
I posted a thread a while ago and cannot find it
If this a duplicate I apologize.

I have been getting started with regex expressions using a tutorial I found on these forums.
Finding number sequences work fine.
Number and alpha give me a problem.
Trying to get a match for:
<body class="content" id="uiW9njI8qPGOt6Hp7wdrNu5">
with variable alpha and numerics.
Tried
<body class="content" id="[a-z][A-Z][0-9]">
<body class="content" id="[a-zA-Z0-9]">
<body class="content" id="\w">
None of witch found a match.
What am I missing?
Thanks
Phil
skil-phil is offline   Reply With Quote
Old 09-30-2022, 09:56 AM   #2
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by skil-phil View Post
What am I missing?
Thanks
A '+' sign.

In Regex, + means "ONE OR MORE of the previous thing".
  • \w = any word or number character
  • \w+ = ONE OR MORE of any word or number character

Or:
  • [a-zA-Z0-9] = Look for a lowercase "a through z", capital "A through Z", or number "0 through 9".
  • [a-zA-Z0-9]+ = Look for ONE OR MORE of lowercase...

You also have other symbols/methods too:
  • \w* = ZERO OR MORE of...
  • \w? = ZERO OR ONE of...
  • \w{4} = EXACTLY 4 of...
  • \w{3,10} = Anywhere between 3 to 10 of...

- - -

Side Note: I'd highly recommend looking at some of my step-by-step breakdowns of regex over the years...

Here's a few of them:

I explain what each piece does, and many times, I even color-coordinate everything with colors to make it easier to understand which piece does what.

You may also want to type this into your favorite search engine:

Code:
 Tex2002ans regular expressions site:mobileread.com
 Tex2002ans regular expressions site:reddit.com
I've written hundreds of posts over the years about regex.

Last edited by Tex2002ans; 09-30-2022 at 10:06 AM.
Tex2002ans is offline   Reply With Quote
Advert
Old 09-30-2022, 10:21 AM   #3
enuddleyarbl
Guru
enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.enuddleyarbl ought to be getting tired of karma fortunes by now.
 
enuddleyarbl's Avatar
 
Posts: 734
Karma: 1077122
Join Date: Sep 2013
Device: Kobo Forma
Quote:
Originally Posted by skil-phil View Post
Hi,
I posted a thread a while ago and cannot find it
If this a duplicate I apologize.

I have been getting started with regex expressions using a tutorial I found on these forums.
Finding number sequences work fine.
Number and alpha give me a problem.
Trying to get a match for:
<body class="content" id="uiW9njI8qPGOt6Hp7wdrNu5">
with variable alpha and numerics.
Tried
<body class="content" id="[a-z][A-Z][0-9]">
<body class="content" id="[a-zA-Z0-9]">
<body class="content" id="\w">
None of witch found a match.
What am I missing?
Thanks
Phil
Since you're working through a tutorial, this might not be what you're looking for. But, my search for <body> tags with stuff in them is simply:
Code:
<body.+?>
If I were to look for something of the form you specified, then I'd try:
Code:
<body class=.+? id=.+?>
or, since the class seems fixed:
Code:
<body class="content" id=.+?>
EDIT: From:
https://regex101.com/
Quote:
. matches any character (except for line terminators)
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)

Last edited by enuddleyarbl; 09-30-2022 at 10:37 AM.
enuddleyarbl is offline   Reply With Quote
Old 09-30-2022, 10:44 AM   #4
skil-phil
Connoisseur
skil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animals
 
skil-phil's Avatar
 
Posts: 57
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
Quote:
Originally Posted by Tex2002ans View Post
A '+' sign.
In Regex, + means "ONE OR MORE of the previous thing".
+lots more
Thanks so much for clarifying this. Worked as you posted.
Will look at your other posts.
Phil
skil-phil is offline   Reply With Quote
Old 09-30-2022, 10:48 AM   #5
skil-phil
Connoisseur
skil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animalsskil-phil is kind to children and small, furry animals
 
skil-phil's Avatar
 
Posts: 57
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
Quote:
Originally Posted by enuddleyarbl View Post
Since you're working through a tutorial, this might not be what you're looking for.
Thanks for the info. Did get it working but alternative solutions are always welcome.
Phil
skil-phil is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pdf regex question - regex that wraps to a new line flyash Conversion 1 09-05-2021 09:00 AM
Regex question rolgiati Calibre 2 11-26-2017 01:58 PM
Yet another regex question Jabby Sigil 8 01-30-2012 08:41 PM
Regex question and maybe some help crutledge Sigil 9 03-10-2011 04:37 PM
Regex Question Archon Conversion 11 02-05-2011 10:13 AM


All times are GMT -4. The time now is 10:31 PM.


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