Results 1 to 5 of 5

Thread: representing a string with Regular Expressions (resolved)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    representing a string with Regular Expressions (resolved)

    As part of an assignment I am trying to represent a string with RE which stands for regular expressions. The string is delimited by double quotes. It can have newline characters at the end. I was wondering if anyone might give me some feedback on if its correct and how to handle the newline characters.

    I have this so far:

    String Literals with RE
    ( " ) ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ) | ( a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z ) ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 )*
    ( a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z )* (newlines will go here) (")

    Anyone know how I can put in newlines and if the rest is correct?
    Last edited by abcdefg; Feb 3rd, 2004 at 02:03 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Well the regular expression you have just posted would match a string like this:

    "f48494990434668646758ndrk\r\n"

    \r\n = New Line

    The regular expression you wrote is similar to saying. Match a string whose first character is a double quotation, the second is a numerical character between 0 and 9 or a lower case letter followed by zero or more numerical characters between 0 and 9 followed by zero or more lower case characters. The string must end in with a double quotation and a newline.

    Rather than writing all the letters and numbers you could do this:

    / "([0-9] | [a-z])[0-9]*[a-z]*"$ /

    The $ symbol mathes the end of line character. Where as [a-z] is a character class representing a range of characters.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149
    My regular expression is supposed to represent any string and the string is delimited by ". It can end with a newline character. Its right I think my question is How do I represent a newline character at the end of the string? I cant use [] $ or other extended RE notation.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by abcdefg
    My regular expression is supposed to represent any string and the string is delimited by ". It can end with a newline character. Its right I think my question is How do I represent a newline character at the end of the string? I cant use [] $ or other extended RE notation.
    It depends on what characters your string can contain. If it is just letters and numbers then a simple:
    Code:
    ((( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ) | ( a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z ) | (A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z))*")+(\n | (\r\n))
    The RE above will match an number of alpha-numeric strings delimited by quotes. \n matches a UNIX style newline and \r\n matches a Wdinwos style newline.

    If you want to match a string which includes any ascii character It would be a little more complicated.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149
    thanx got it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width