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
  • Pattern Check Match

    regex windows-admin help tutorial learning
    13
    0 Votes
    13 Posts
    37 Views
    M
    why not this? ^[A-z]+\.[A-z]+\d{1,2}$
  • 0 Votes
    16 Posts
    76 Views
    R
    Using RegexBuddy (yeah, I guess I am falling into a hole here) the POSIX notation is perfectly acceptable, hence your [:alnum:]. I can substitute [:alpha:] there as well and I suspect others in the list are good actors. My brain infarct occurs though when I use Herr Gevertz' table of translations and try to replace the POSIX with his ASCII ([a-zA-Z0-9]) or for that matter UNICODE ([\p{L}\p{Nl}\p{Nd}]), neither of which work in his interface. Grand tool, RegexBuddy ... it's one of those feature-rich interfaces which swim with example/sample in the help volume. My only complaint is that searching through documentation for words has no highlight of the found set so I've got to print out the page and use my pdf search to locate all instances!
  • learning regex isn't easy :-)

    regex com learning
    7
    0 Votes
    7 Posts
    41 Views
    J
    So given that you just want to mess around with regex. Kardock wrote: but it fails. Presumably you mean it runs but it does not successfully match. The problem is '\w' is not an expression that could ever match an email. So you need to look up what it does match. The other problem that you will find is that attempting to actually match a valid email is very difficult. The regex to do it is about 1000 characters long. You can google that both to see what a long regex looks like and to educate yourself what a 'valid' email actually is. (I do it every couple of years to remind myself especially when someone says they want to 'validate' an email.) However you don't need to match an email. What you need to match is the fourth value in the list. So the way to match that is the following [^;]+ You should probably in fact match all of the columns that way. So you should study that expression to figure out what it does. And then answer for yourself why the other posters comment about embedded semi-colons being a problem.
  • Exclude already masked data in regex

    regex help tutorial question
    3
    0 Votes
    3 Posts
    24 Views
    N
    hey Terry, Thanks for the suggestion. I am trying to achieve this patter replacement in java This one I thought of it but it is not working out for the input *1234 x1234 -1234 these kind of inputs should not be masked and output should be as it is *1234 / x1234 / -1234 whatever you have given works fine for *12345678 x12345678 -12345678
  • Regex search and replace? Tabs ...

    tools regex help tutorial question
    2
    0 Votes
    2 Posts
    19 Views
    J
    Member 14835146 wrote: But it's very time-consuming That is not specific. As in it takes 10 seconds? Or 10 hours? Regexes meet specific needs but speed is not necessarily one of them. For starters a regex is always interpreted in the process. Even 'compiled' ones still end up in a form that is at best halfway to an actual compiled solution. And your problem is in fact something that likely could be solved by real code. So that is likely something that would be faster. But other than that it appears you might be attempting to do a regex solution for an entire file ('document') rather than doing it line by line. If you do in fact have lines which have a fixed number of timestamps then looping might provide a better solution especially if you can anchor the regex.
  • RegEx remove duplicate need help

    regex help tutorial question
    6
    0 Votes
    6 Posts
    38 Views
    J
    trønderen wrote: are you serious about using a regex to compare entire text lines for being identical Myself? No I would not have attempted it with regex at all. I probably would have created a one shot perl script, not for the regex capabilities, but rather because reading files is easier to set up. And running it for iteration testing is easier also. And I would note that the editor I use does have a fairly decent regex. So the lack of that would not have impacted my decision.
  • 0 Votes
    4 Posts
    24 Views
    J
    Piotr Przeklasa wrote: How to insert a space at the beginning of a line in a "for next" code loop (.NET regular expressions) Nope. Wrong way to attempt this. This is a common assumption that regex can handle this but the very nature of regex processing precludes it. You need to do it with regular code. The limits of using regex start showing up with recursion problems. For example the following. for line of code for line of code next line of code line of code next
  • Need help with Regular expression

    regex help question
    3
    0 Votes
    3 Posts
    11 Views
    J
    Use code tags when you post code on this site. Why there is a double quote in what you posted?
  • Redirection with exclusions RegEx

    php sysadmin regex help question
    1
    0 Votes
    1 Posts
    6 Views
    No one has replied
  • I need help with a complex regex

    regex help tutorial question
    8
    0 Votes
    8 Posts
    30 Views
    L
    No, my suggestion was to abandon the use of Regex patterns. You can easily split the string into an array of strings separated by spaces. All words before an entry of "b." are parts of the name. All words after the "b." and before "d." or the end of the text, relate to the birth date. All items after "d." relate to the date of death. And apart from anything else it makes your code much clearer.
  • What is the regular expression for this string?

    regex question database
    5
    0 Votes
    5 Posts
    24 Views
    J
    Member 15959121 wrote: Microsoft.Sql/servers/*.*/databases You are misusing the asterisk. It matches the preceding element only. which in this case is the forward slash. Moreover it matches zero or more. Which is probably not what you want. However you also said... "Microsoft.Sql/servers/" and "/databases" should be an exact match So the first attempt at a fix, which is not correct, would look like the following. (Microsoft.Sql/servers/)?.*/databases But that is limited then because it does not match the second expression. You might think the following is a good idea but do NOT do this. You should never create a regex in which everything is optional. (Microsoft.Sql/servers/)?.*(/databases)? You would need to use an or ('|') with 3 expressions (match first, match last, match all) which to me is way too confusing from the maintenance standpoint. It is not even clear to me if you have defined your match space. Presuming the following are NOT valid Microsoft.Sql/servers/xxx xxx/databases Then I would do the following (pseudo code) if match just: Microsoft.Sql/servers else if match just: /databases else match: Microsoft.Sql/servers/.*/databases But additionally note even the above matches the following which is probably not what you want. Microsoft.Sql/servers///\\&4xz /databases/servers/databases
  • 0 Votes
    3 Posts
    10 Views
    L
    Thanks for prompt reply. Unfortunately I need to limit my reply... I had an eye surgery and having a heck of a time reading small font... and there is no easy way to set EVERYTHING to larger font... each app has it own setting... I should have thought about that BEFORE getting my eyeballs refurbish... Now if I use CAPS some people will get offended.... again... CHEERS
  • 0 Votes
    4 Posts
    19 Views
    J
    Member 15942356 wrote: but I can't help feeling that there is a better way Probably there is a better way unless you really only want the key and will not want anything else. If you are going to want something else (or several things) then the better way is to write (or find) and actual parser. So code, not just regex, which parses files based on the structure specified from the spec.
  • 0 Votes
    5 Posts
    22 Views
    J
    This is an example of why I always insist on tabs as a separator (not commas nor semi-colons.) Guus2005 wrote: Remove all double quotes not directly preceded or directly followed by a semicolon You are trying to solve this incorrectly. Guus2005 wrote: 1;200;345;"Apotheker "Blue tongue"";"Apeldoorn";12;"ABCD12" You do not want to "remove" the double quotes because they are part of the value. The following is the correct value from the above. Apotheker "Blue tongue" The pattern for the CSV is as follows 1. Semi-colon separates values. 2. Some values are quoted (double quotes.) For processing for the second case the following applies for the value (not the line but just a value from the line.) 1. The double quotes MUST be at both the end and start of the value. It is ignored if both are not true. 2. The double quotes in that case are removed. Double quotes internal are not impacted. Additionally you need to deal with the potential that there is a semi-colon in the middle of a value. If there is a semi-colon in a value then I doubt you should be using a regex to parse lines. Certainly if I was doing it I would not use a regex. Rather I would build a parser/tokenizer since the rules would be easier to see (and debug). Additionally it would probably be faster also. The tokenizer makes the case with the semi-colon much easier to deal with. The tokenizer rule would be in general 1. Find a semi-colon (start at semi-colon.) 2. If the next character is a double quote, flag a rule that it must look for quote then semi-colon as next break. 3. If the next character is not a double quote, flag a rule that it must look for a semi-colon as next break.
  • regex expression for us addresses

    regex java debugging json
    8
    0 Votes
    8 Posts
    29 Views
    J
    trønderen wrote: a 'state' level between the city and the country If that shows up then you probably need to educate the requirements writer.
  • Well no that isn't how it works

    regex help perl html hardware
    1
    0 Votes
    1 Posts
    5 Views
    No one has replied
  • Problem combining REGEX expressions

    help regex php com question
    3
    0 Votes
    3 Posts
    15 Views
    J
    I didn't attempt to parse that but there seems to be several constructs in there that would make me nervous. You have two '$' and only one '^' It appears you have two optional clauses. Optional clauses without hard anchors general are always a problem because they likely make the regex engine do a lot of work. Since you already presumably have a working solution what makes you think you need to combine them into one expression? Or another way of saying that is that regexes use an iterative process to find the best solution and more complex expressions unless carefully crafted can cause unexpected problems (slowness.)
  • 0 Votes
    3 Posts
    14 Views
    J
    You did not define which regex you are working with. Your definition for the 'word' is anything except a space. Which is not really what 'word' generally means. But that is what I used. In perl. m[^ ]+ The above will match the following (because that is the definition of 'word') m&extra---stuff. It is also limited with the following since, again with the definition of word, it is not clear what might be expected mFirst,mSecond
  • RegEx- Find files in Linux which match the expression

    regex com linux tutorial
    4
    0 Votes
    4 Posts
    15 Views
    J
    Thanks K5054, that was the clincher. To find the files I need, I had to perform the following: * State the Regex Engine as 'posix-extended' * Put the expression '.*' at the start of the filename as the files are treated as fully qualified filenames (file path & filename). Thus, I can now use the following: find /storage/log/vmware/ -type f -regextype posix-extended -regex '.*vpxd-svcs-access-.2022-[0-9]{2}-[0-9]{2}.log.gz' And.... find /storage/log/vmware/ -type f -regextype posix-extended -regex '.*sps.log.[0-9]{2}.gz' | +-- JDMils | +-- VB6 +-- VB Dot Net |
  • 0 Votes
    3 Posts
    14 Views
    M
    Thanks Original Griff, That is beyond my technical know-how at this point but I am looking to learn. I am using this within Octoparse which from what I have learnt to date can only use regex to make the fields absolute / more accurate. So I think I am stuck with trying to make it work using regex. Unless anyone knows differently or can help with the regex please?