Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Literal strings and patterns

Last post 07-09-2008, 7:12 PM by Aussie Susan. 4 replies.
Sort Posts: Previous Next
  •  07-08-2008, 1:13 AM 43854

    Literal strings and patterns

    Hi -- how would I accomplish the following:

    * Create a regular expression that matches the number 10

    * Create a regular expressions to match text between underscores.  As an example, I would like to parse the string: '34_fgh95_batch_7645_rdf4er2.pdf' to obtain '34' the characters between the beginning of the string and the first underscore.  Then create another expression to match 'fghh95', the characters between the first and second underscores.  The same would apply for 'batch' and 'rdf4er2'

     

    Thanks in advance.

  •  07-08-2008, 7:18 PM 43916 in reply to 43854

    Re: Literal strings and patterns

    If you want to match the character string representation of the number ten (and I'm not being pedantic here - regex's only match characters and have no concept of numbers or anything else) the the pattern:

    10

    will find the two consecutive characters '1' and '0' anywhere within the text. If you  don't want it to find the '10' within "341065" then something like:

    \b10\b

    will work in many cases (but it will still find the '10' in "abc-10-def"). This all goes to show that you need to fully understnad and explain what you aer after.

    As for finding each of the sub-strings between the underscores, I would suggest that you use the regex split function using the underscore as the pattern. Note that this will produce 'rdf4er2.pdf' as the last component and not 'rdf4er2' as in your example.

    Susan 

  •  07-09-2008, 12:05 AM 43929 in reply to 43854

    Re: Literal strings and patterns

    http://regexadvice.com/blogs/mash/archive/2007/06/01/Are-you-ready-for-regex_3F00_.aspx

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  07-09-2008, 5:42 PM 43973 in reply to 43929

    Re: Literal strings and patterns

    Thank you for all the wonderful advise, does anyone know where to find an excellent regular expresion tutorial?

     

    Regards

  •  07-09-2008, 7:12 PM 43975 in reply to 43973

    Re: Literal strings and patterns

    A Google search for 'regex tutorial' brings up a whole lot of hits. Some are generic (e.g. http://www.regular-expressions.info/tutorial.html) while others are specific to the regex engine you are using.

    Susan 

View as RSS news feed in XML