Skip to content

Regular Expressions

Regular Expressions discussions

This category can be followed from the open social web via the handle regular-expressions@forum.codeproject.com

188 Topics 829 Posts
  • Editing my existing Regex

    regex help question
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • 0 Votes
    1 Posts
    3 Views
    No one has replied
  • regex to replace accents

    regex
    9
    0 Votes
    9 Posts
    19 Views
    Richard DeemingR
    Regex can do the job. But running five+ separate regex operations on a string just to replace a few letters with their unaccented alternatives is overkill. The other option, which is even nastier and less obvious, is to use Unicode normalization: static string RemoveDiacritics(string stIn) { string stFormD = stIn.Normalize(NormalizationForm.FormD); StringBuilder sb = new StringBuilder(); for(int ich = 0; ich < stFormD.Length; ich++) { UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD\[ich\]); if (uc != UnicodeCategory.NonSpacingMark) { sb.Append(stFormD\[ich\]); } } return sb.ToString().Normalize(NormalizationForm.FormC); } string input = "Príliš žlutoucký kun úpel dábelské ódy."; string result = RemoveDiacritics(input); // "Prilis zlutoucky kun upel dabelske ody." Source[^] "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • 0 Votes
    1 Posts
    4 Views
    No one has replied
  • Trying to match a string with many backslashes

    question regex
    2
    0 Votes
    2 Posts
    6 Views
    Richard DeemingR
    Assuming you want to extract three strings: \abc\rvr\sad\dqwdwq \rfdqwdvr\rtgevr\rgwvrr\23rvrv \rffewvr\rfewvr\rvfewrr\rvrwefewv Try: ([\\][A-Za-z0-9]+)+ Regexper[^] "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • Regex to match exact word and dash symbol

    regex question
    10
    0 Votes
    10 Posts
    21 Views
    L
    Without full samples relating to your posted question, Im really afraid nobody is going to help you. This site shows how my regex matches what you said needs to matched. https://regex101.com/r/cH4Jrg/1 Feel free to experiment with it, if that's easier than trying to describe what should be matched.
  • Problem capturing last group in a line: CLOSED

    help regex question
    3
    0 Votes
    3 Posts
    9 Views
    M
    Thank you for your help :)
  • Employer Identification Number (EIN) Regex

    regex help tutorial question
    4
    0 Votes
    4 Posts
    12 Views
    L
    To prevent (Capturing|Groups), you can spec them as (**?:**Non|Capturing|Groups)
  • Regex select from list

    help tutorial regex question
    2
    0 Votes
    2 Posts
    7 Views
    J
    Jukec wrote: "[node=\\d+]" No idea what language that is in. But all of the major ones use the same regex semantics for the most part. The square brackets should not be there. Presumably the rest of the code is actually going to 'capture' what is matched. That is a specific term for regex. If so it will look like 'node=16700222031' which means you would need to parse it again to get the number out.
  • 0 Votes
    6 Posts
    10 Views
    L
    With the sample text-strings you've provided, its impossible for any expression to match by 'internal' domain. If your application has a %variable% to represent the domain being searched, you would have to provide this. Regex simply matches text, it cant determine if that text is "the domain being searched" by your application. I've seen apps that support variables like %domain% in their match-expressions, but they're specific to that application. So if your app supports this, you'd have to look up the variable-name in the documentation, to provide a working example. Short of that, you would need to either hard-code the domains per site being searched, like in the example provided. Or include a larger snippet of the html, but only if the html offered another way to verify 'internal' (highly unlikely). Sorry for the news, but regex wont solve this without 'internal' being defined, whether by a previous match, or by some variable. Some apps even let you customize variables, so maybe thats another option? Sorry, but I know nothing of this "Screaming Frog". Either way, I do wish you luck!
  • Interrupted list

    regex help tutorial question
    5
    0 Votes
    5 Posts
    14 Views
    L
    Greetings Dumitru, Im not expert because there seems to be many different flavors, so Im just guessing on this. But it does seem like each "semicolon-comma pair" could be represented by something like ... (\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, ) So depending on your flavor, since the sample has 4-1/2 pairs, you might have to type a VERY long string like... ^([\w]+\. )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, )(\d{1,2}(?:[-:]\d{1,2}[a-z]?)?; )(\d{1,2}:\d{1,2}(?:[a-z]|-\d\d)?, \d{1,2}(?:[-:]\d{1,2}[a-z]?)?;)$ With a replacement like... \1\2\1\3\4\1\5\6\1\7\8\1\9
  • Need some help with regular expression

    regex help tutorial question
    10
    0 Votes
    10 Posts
    9 Views
    L
    If this matches to much, I would need more samples to know what 'should' and 'should not' be matched... ^\d{1,2}[-,A-Z\d]{0,5}$
  • 0 Votes
    5 Posts
    12 Views
    R
    Needed to turn on the global flag... Thank you!
  • Regex to detect href not correctly closed

    regex question career
    3
    0 Votes
    3 Posts
    10 Views
    M
    Ok Richard, thaks a lot ;)
  • What Could Be RegExp For?

    testing beta-testing regex tutorial question
    2
    0 Votes
    2 Posts
    4 Views
    P
    The \s+ in that regex will only match a single string of one or more consecutive whitespace characters, not "all spaces" So your regex would match "This test" or "This      test" but not "This is testing" There are lots of online regex builders and analysers, which I suggest you seek out. Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
  • 0 Votes
    3 Posts
    5 Views
    P
    The commonest way that people solve this for browsers that don't support this is to think in reverse. In other words, you reverse the string and the regular expression so that all you end up testing is the negative regular expression, rather than a lookbehind. This[^] is a great resource. Advanced TypeScript Programming Projects
  • Regex for a Customer number

    regex sales help
    3
    0 Votes
    3 Posts
    9 Views
    J
    Following should do it in perl, java and C#. ^[0-9]{5}$
  • Ignoring repeating values?

    sysadmin regex question
    4
    0 Votes
    4 Posts
    9 Views
    J
    Jason Hotchkiss 2021 wrote: Is it possible to capture the remained words into a single group? How about /(C\w+=|[[\]])/g ?
  • Replace certain characters in part of string?

    regex question help tutorial
    5
    0 Votes
    5 Posts
    14 Views
    W
    Great, that was exactly what i was looking for, thank you so much, Richard! So, to solve the problem from my original posting, that is to match all spaces after the first "v" in the string "I want to solve this problem", this Regex works: /(?<=v.*) /g
  • Regex only want the first match

    regex database
    2
    0 Votes
    2 Posts
    5 Views
    A
    Can you explain more what you're trying to do? Also, what tools/language are you using?