Regex and using string regular expressions

csharp United States
  • 15 years ago

    I'm afraid I don't know this language (it comes from Pearl) but would like to use it to do a
    simple task and I don't have time to learn it.


    Could anyone tell me what's the regular expression to find the tag where the
    tag is defined as starting with [* and ending with *]


    e.g. [address]


    Thanks for any help.


    BTW - I've written the C# code so I don't need any help with that.

  • 15 years ago

    ([*\w+*])


    this will take


    [address]  is correct



    [vas]jhhds[kum]


    resulting matches is


    [vas]
    [kum]


    \w means anyAlphabets or numeric(0-9) and A-Z or a-z



  • 15 years ago
    I'm using :

    string tagFormat = "(\\[\\*\\w+\\*\\])";
    regex = new Regex( tagFormat );

    .....

    MatchCollection tags = regex.Matches( line );

    No matches are found.

    Any ideas?

    Thanks
  • 15 years ago

    [*.+?*]

  • 15 years ago
    Quote:
    [1]Posted by d9930380 on 16 Jun 2005 11:25 AM[/1]
    I'm using :

    string tagFormat = "(\\[\\*\\w+\\*\\])";
    regex = new Regex( tagFormat );

    .....

    MatchCollection tags = regex.Matches( line );

    No matches are found.

    Any ideas?

    Thanks
    When you need to escape several characters, I'd suggest putting an "@" symbol before your string.  This tells the compiler to treat the entire string as literal, e.g. string tagFormat = @"(\[\*w+\*\])";.  This makes your string much easier to read.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou