regex

Parse arbitrary delimiter character using Antlr4

 ̄綄美尐妖づ 提交于 2021-02-09 15:16:44
问题 I try to create a grammar in Antlr4 that accepts regular expressions delimited by an arbitrary character (similar as in Perl). How can I achieve this? To be clear: My problem is not the regular expression itself (which I actually do not handle in Antlr, but in the visitor), but the delimiter characters. I can easily define the following rules to the lexer: REGEXP: '/' (ESC_SEQ | ~('\\' | '/'))+ '/' ; fragment ESC_SEQ: '\\' . ; This will use the forward slash as the delimiter (like it is

Parse arbitrary delimiter character using Antlr4

a 夏天 提交于 2021-02-09 15:09:46
问题 I try to create a grammar in Antlr4 that accepts regular expressions delimited by an arbitrary character (similar as in Perl). How can I achieve this? To be clear: My problem is not the regular expression itself (which I actually do not handle in Antlr, but in the visitor), but the delimiter characters. I can easily define the following rules to the lexer: REGEXP: '/' (ESC_SEQ | ~('\\' | '/'))+ '/' ; fragment ESC_SEQ: '\\' . ; This will use the forward slash as the delimiter (like it is

Changing “firstname lastname” to “lastname, firstname”

妖精的绣舞 提交于 2021-02-09 11:10:38
问题 I have a list of names that I need to convert from "Firstname Lastname" to "Lastname, Firstname". Barack Obama Donald J. Trump J. Edgar Hoover Beyonce Knowles-Carter Sting I used G. Grothendieck's answer to "last name, first name" -> "first name last name" in serialized strings to get to gsub("([^ ]*) ([^ ]*)", "\\2, \\1", str) which gives me - Obama, Barack J., DonaldTrump, Edgar, J.Hoover, Knowles-Carter, Beyonce Sting What I would like to get - Obama, Barack Trump, Donald J. Hoover, J.

Changing “firstname lastname” to “lastname, firstname”

我与影子孤独终老i 提交于 2021-02-09 11:08:36
问题 I have a list of names that I need to convert from "Firstname Lastname" to "Lastname, Firstname". Barack Obama Donald J. Trump J. Edgar Hoover Beyonce Knowles-Carter Sting I used G. Grothendieck's answer to "last name, first name" -> "first name last name" in serialized strings to get to gsub("([^ ]*) ([^ ]*)", "\\2, \\1", str) which gives me - Obama, Barack J., DonaldTrump, Edgar, J.Hoover, Knowles-Carter, Beyonce Sting What I would like to get - Obama, Barack Trump, Donald J. Hoover, J.

grep multiple patterns single file argument list too long

大憨熊 提交于 2021-02-08 23:41:13
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

grep multiple patterns single file argument list too long

浪尽此生 提交于 2021-02-08 23:40:47
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

Validate UUID Restful service

≡放荡痞女 提交于 2021-02-08 20:54:09
问题 I have a RESTful service which receives POST request with UUID values and writes them in DB. So the problem is to validate if UUID is valid or not. For this purpose I implemented custom annotation: @Constraint(validatedBy = {}) @Target({ElementType.FIELD}) @Retention(RUNTIME) @Pattern(regexp = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}") public @interface validUuid { String message() default "{invalid.uuid}"; Class<?>[] groups() default {}; Class<?

PHP using preg_match or regex as value for array_search or the key for array_keys_exist

拈花ヽ惹草 提交于 2021-02-08 20:53:29
问题 I was wondering if it was possible to use regex or preg_match() in array_seach() or array_keys_exist ? ie. array_keys_exist($array,"^\d+$") to match all keys that are solely numeric characters 回答1: I don't know whether it suits your needs exactly, but you should have a look at the preg_grep function, which will check an array of strings against a regex and return all matching array elements. You could do same with the keys, by using preg_grep on the return value of array_keys. This is

Regex to match multiple words in any order

久未见 提交于 2021-02-08 20:52:22
问题 I'm writing a python script which will mark output for a Windows CIS benchmark. In order to do this I am matching values in group policy settings with a regex to see if they meet the criteria for the benchmark. For certain aspects of the benchmark it is necessary for a list of users to present in the setting, but it must be exclusive and the order they are specified does not have to be consistent. As an example, 'Adjust memory quotas for a process' should be Administrators,LOCAL SERVICE

Regex to match multiple words in any order

十年热恋 提交于 2021-02-08 20:52:07
问题 I'm writing a python script which will mark output for a Windows CIS benchmark. In order to do this I am matching values in group policy settings with a regex to see if they meet the criteria for the benchmark. For certain aspects of the benchmark it is necessary for a list of users to present in the setting, but it must be exclusive and the order they are specified does not have to be consistent. As an example, 'Adjust memory quotas for a process' should be Administrators,LOCAL SERVICE