regular expressions

  1. 4 years ago

    [deleted]

    20 Apr 2015

    hi!

    Is any of you guys good with regular expressions?
    I'd need a bit of help here in using them for replacing different varieties of words.

    Could anyone help me out with it?

  2. @ameo hi!

    Is any of you guys good with regular expressions?
    I'd need a bit of help here in using them for replacing different varieties of words.

    Could anyone help me out with it?

    Can you give an example of what you're looking to do? I'm familiar with it (good is debatable ;)) so I should be able to help.

  3. [deleted]

    20 Apr 2015

    ok. I have this:

       <RegEx find="(uslov)(a|e|i|u|om|ima)" replaceWith="uvjet$2"/>

    and what puzzles me is why
    "uslov" isn't replaced with "uvjet"

    and also, how could i set this up properly so that it doesn't matter if letter is big or small,
    it changes word anyway?

  4. Thirtysixway

    20 Apr 2015 Moderator Answer

    @ameo ok. I have this:

       <RegEx find="(uslov)(a|e|i|u|om|ima)" replaceWith="uvjet$2"/>

    and what puzzles me is why
    "uslov" isn't replaced with "uvjet"

    and also, how could i set this up properly so that it doesn't matter if letter is big or small,
    it changes word anyway?

    The way it's written, it's required to have the 2nd portion. So because uslov doesn't have a/e/i/u/om/ima, it doesn't match. Try adding * which will make it match 0 or more of the previous regex.

       <RegEx find="(uslov)(a|e|i|u|om|ima)*" replaceWith="uvjet$2"/>

    I'm not sure how it behaves if $2 is missing, as in uslov there's no value for $2 generated.

    As far as whether or not it's case sensitive, I'd have to see what software you're using. Typically it's adding the i modifier to the end of the expression but I don't see that option with the syntax you posted. For example in a normal regex for what I posted would be

    s/(uslov)(a|e|i|u|om|ima)*/uvjet$2/

    And to be case insensitive you'd use

    s/(uslov)(a|e|i|u|om|ima)*/uvjet$2/i

    One possible solution would be to do something like this.. though it's really messy and there is probably a better way to do it :)
    ([uU][sS][lL][oO][vV])([aA]|[eE]|[iI]|[uU]|[oO][mM]|[iI][mM][aA])*

  5. [deleted]

    20 Apr 2015

    first part answered my question, which is great, so thank you.

    2nd part I think you misunderstood, because it's not about that word,
    but about all words - basically when they're first in sentence and with big letter,
    this fails to change them, and that /i doesn't help.

    I work in .xml [program's language is c#]

  6. @ameo first part answered my question, which is great, so thank you.

    2nd part I think you misunderstood, because it's not about that word,
    but about all words - basically when they're first in sentence and with big letter,
    this fails to change them, and that /i doesn't help.

    I work in .xml [program's language is c#]

    Okay, in that case I'm not sure I can help (I don't know C#) but this page seems like it has some useful info
    http://stackoverflow.com/questions/2439965/case-insensitive-regex-without-using-regexoptions-enumeration

  7. [deleted]

    20 Apr 2015

    ok, I'll try that. thank You.

    @Thirtysixway could you please tell me how do I incorporate this properly in my examples?
    I try and try again but I don't get wanted results, but lots of failed replaces instead.

 

or Sign Up to reply!