Re: Finding formatting items in a string



Hello Jack,

I even found a FAQ on this... I'm going to write a blogpost about this pattern at some poitn I guess. It has a lot of interesting regex things in it.

The FAQ:
http://msdn2.microsoft.com/en-us/netframework/aa569608.aspx

And a further completed regex, including the fact that you can use { and } within the custom pattern if you want to... Just escape them again. Which makes the whole escaping { harder and harder to understand...

This is the expression I've got so far:
(?<!([^\{]|^){({{)*){(?<item>[0-9]+)(?<alignment>,[-+]?[0-9]+)?(?<format>:([^{}]|{{|}})+)?}(?!}({{)*([^}]|$))

note also that I removed the \ before most, if not all of the { and } in the expression. It seems that the .NET regex parser is quite content with this. Only if the {n(,(m)?)?} format is used, do you need to escape the { and the }. I found that by accident. Not that it makes the expression any easier to read... *sigh*...

--
Jesse Houwing
jesse.houwing at sogeti.nl


.



Relevant Pages

  • Re: Help with Regex and trying to mimic the VB "like" comparison
    ... I'd suggest using Regex.Escape(...) to escape all the meta-characters in the ... just allow the pattern the user types be the ... pattern for the regex, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: oniguruma : cant get it to search for (backslash)
    ... ArgumentError: Oniguruma Error: end pattern at escape ... In a regex literal a backslash is a metacharacter, ...
    (comp.lang.ruby)
  • Re: How to search/match a variable pattern
    ... there are some meta-characters, \:, that I need to escape, but how do I escape ... whether I found a match of a particular string on $path and do not need to ... Or do I get the regex logic all wrong ... ... The one liner is just a test on whether am using the pattern matching correctly ...
    (perl.beginners)
  • Re: RegEx challenge - doesnt work
    ... Doesn't anyone lurk and read the FAQ ... > you'll get an array foreach grouping eachtime the pattern is ... try splitting vs regex ...
    (comp.lang.perl.misc)
  • Re: How to search/match a variable pattern
    ... upper case both the string and the pattern that I am searching for. ... You probably have regex meta-characters in $pattern that need to be escaped. ...
    (perl.beginners)