Jump to content

Regex 1


Removed #5

Recommended Posts

I'm fighting regular expressions - some seem straight forward - this one is giving me fits.
Desired replacement (vb.net regex.replace) for a string:

  • begins with either a "("or a "["  [\(\[]
  • possibly a space \s?
  • probably a "v" v?
  • possibly a space \s?
  • possibly an integer  \d* <- the problem part
  • possibly a period or space [\.\s]
  • possibly another integer \d*
  • possibly a space \s?
  • then the closing ( or [  [\]\)]

so the regex should look like [\[\(]v?\s?\d*[\.\s]?\d*\s?[\)\]]

okay, so I left the initial space (2) out and changed the regex to [\[\(]\s?v?\s?\d*[\.\s]?\d*\s?[\)\]] which seems to work.  Why did it not present - until the first digits portion of the regex??
 
This is replacement text in the file name of a book, typically the "version" number of a scanned ebook so there will probably be text before or after the string to be replaced (for testing I'm doing a replace with a "$").
given as input:
 (22.5)
only (v 5.6) one
(v1.5)
some ( v .5 ) stuff
(v15)
 
and I'm getting:
$¶
only $ one ¶
$¶
some ( v .5 ) stuff¶
$¶

 

Any ideas what I'm doing wrong in there, cause I can't see it???

Edited by Al Jones
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy , along with dressing your husky as a unicorn on the first Thursday of each month