regex ex problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • philipl@vistatec.ie

    regex ex problem

    hi,

    does any one how to do regex to get the charset in this strings?

    "SCRIPT language="JavaS cript"
    charset="ISO-8859-1">..."...."... "...">?"
    ^^^^^^^^^^
    I want the value after charset, (charsets value is not consistant) I
    am having problems with the following regexp, I don't know at compile
    time what will be after the iso number,I can't seem to be able to
    describe the ending conditions, the multiple "s causes too much string
    to be returned:

    tag = "charset";
    Regex r = new Regex(tag+"\\s* =\\s*\"?(.*)\"? ");

    thx
  • Jerry Negrelli

    #2
    regex ex problem

    If you're trying to capture the value of the charset
    attributes, this will do that:

    new Regex(@"charset \s*=\s*\"?([^\"]*)");

    Keep in mind this code will find charset anywhere in your
    document and return andthing inside of the quotes that
    follow. If quotes are optional, you'll have to modify
    that regex a bit.

    Good luck!

    Jerry Negrelli
    [color=blue]
    >-----Original Message-----
    >hi,
    >
    >does any one how to do regex to get the charset in this[/color]
    strings?[color=blue]
    >
    >"SCRIPT language="JavaS cript"
    >charset="ISO-8859-1">..."...."... "...">?"
    > ^^^^^^^^^^
    >I want the value after charset, (charsets value is not[/color]
    consistant) I[color=blue]
    >am having problems with the following regexp, I don't[/color]
    know at compile[color=blue]
    >time what will be after the iso number,I can't seem to[/color]
    be able to[color=blue]
    >describe the ending conditions, the multiple "s causes[/color]
    too much string[color=blue]
    >to be returned:
    >
    >tag = "charset";
    >Regex r = new Regex(tag+"\\s* =\\s*\"?(.*)\"? ");
    >
    >thx
    >.
    >[/color]

    Comment

    Working...