regex-group

Java Regex inconsistent groups

不羁的心 提交于 2019-12-11 23:37:19
问题 Please Refer to following question on SO: Java: Regex not matching My Regex groups are not consistent. My code looks like: public class RegexTest { public static void main(String[] args) { // final String VALUES_REGEX = "^\\{([0-9a-zA-Z\\-\\_\\.]+)(?:,\\s*([0-9a-zA-Z\\-\\_\\.]*))*\\}$"; final String VALUES_REGEX = "\\{([\\w.-]+)(?:, *([\\w.-]+))*\\}"; final Pattern REGEX_PATTERN = Pattern.compile(VALUES_REGEX); final String values = "{df1_apx.fhh.irtrs.d.rrr, ffd1-afp.farr.d.rrr.asgd, ffd2

Whatsapp chat log parsing with regex

╄→гoц情女王★ 提交于 2019-12-11 19:28:35
问题 I'm trying to parse a whatsapp chat log using regex. I have a solution that works for most cases but I'm looking to improve it but don't know how to since I am quite new to regex. The chat.txt file looks like this: [06.12.16, 16:46:19] Person One: Wow thats amazing [06.12.16, 16:47:13] Person Two: Good morning and this goes over multiple lines as it is a very long message [06.12.16, 16:47:22] Person Two: :: While my solution so far would parse most of these messages correctly, however I have

Why doesn't my function correctly replace when using some regex pattern

て烟熏妆下的殇ゞ 提交于 2019-12-11 17:46:24
问题 This is an extension of this SO question I made a function to see if i can correctly format any number. The answers below work on tools like https://regex101.com and https://regexr.com/, but not within my function(tried in node and browser): const const format = (num, regex) => String(num).replace(regex, '$1') Basically given any whole number, it should not exceed 15 significant digits. Given any decimal, it should not exceed 2 decimal points. so... Now format(0.12345678901234567890, /^\d{1

Regex to get method parameter name

安稳与你 提交于 2019-12-11 15:20:16
问题 Need regular expression to replace only parameter name. By program i am able to fetch the parameter name but while replacing it using regular exression , its failing when we have both parameter class and parameter name as same. like below method: getCustomerCyclesListInfo( CustomerCyclesListInfo CustomerCyclesListInfo, CustomerCyclesListInfo CustomerCyclesListInfo) i tried with below regex but its matching all four in above : (?<!\()\b(CustomerCyclesListInfo)\b i want that word starting with

Return only one group with OR condition in Regex

我怕爱的太早我们不能终老 提交于 2019-12-11 15:17:24
问题 I have to write a Regex to fetch Email Address from a sentence. I want it to be returned with Group 1 only. Regex: \[mailto:(.+)\]|<(.+@.+\..+)> Input String: Hello my Email Address is <foo@hotmail.com> - Return foo@hotmail.com as Group1. Hello my Email Address is [mailto: foo@hotmail.com] - Return foo@hotmail.com as Group2. I want if any of the string matches then it should be returned in Group1. Is there any way to do this? 回答1: You may use regular expression: (?=\S+@)([^<\s]+@.*(?=[>\]]))

Can I use re.sub (or regexobject.sub) to replace text in a subgroup?

三世轮回 提交于 2019-12-11 14:12:51
问题 I need to parse a configuration file which looks like this (simplified): <config> <links> <link name="Link1" id="1"> <encapsulation> <mode>ipsec</mode> </encapsulation> </link> <link name="Link2" id="2"> <encapsulation> <mode>udp</mode> </encapsulation> </link> </links> My goal is to be able to change parameters specific to a particular link, but I'm having trouble getting substitution to work correctly. I have a regex that can isolate a parameter value on a specific link, where the value is

Detection of only the number in regex

*爱你&永不变心* 提交于 2019-12-11 09:33:51
问题 I have the following regex : (?<!__num)10\b and when I want to detect 10 from the following sentence can there be B110\ numbers and 10 numbers in this sentence the following is returned can there be B1 10 \ numbers and 10 numbers in this sentence but I do not want 10 to be detected inside 110, so I changed the regex to [^\d+](?<!__num)10\b In that case, the result returned with 10 preceding a space character. I want only the number given in the regex to be identified. For example, If I give

Remove text after second colon

橙三吉。 提交于 2019-12-11 07:25:07
问题 I need to remove everything after the second colon. I have several date formats, that need to be cleaned using the same algorithm. a <- "2016-12-31T18:31:34Z" b <- "2016-12-31T18:31Z" I have tried to match on the two colon groups, but I cannot seem to find out how to remove the second match group. sub("(:.*){2}", "", "2016-12-31T18:31:34Z") 回答1: A regex you can use: (:[^:]+):.* which you can check on: regex101 and use like sub("(:[^:]+):.*", "\\1", "2016-12-31T18:31:34Z") [1] "2016-12-31T18

How to disassemble a string with CaptureGroup “(.+?:[\/\\]+)”?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 06:47:56
问题 A given string: dec:/file1.texdec:/file2.srcdec:/file3.ltx\ndec:/file4.dtxdec:/file5.insdec:/file6.src contains concatenated file paths. (The length of the volume name (here: dec) is variable. Pay attention to the line break in the string.) With the RegExp (.+?:[\/\\]+) (without g and without m options) I get the CaptureGroup \1 dec:/ . (If the volume name is only c the CaptureGroup contains c:/ . With path containing \ instead of / the CaptureGroup also contains dec:\ or c:\ .) How can I

Matlab regular expressions capture groups with named tokens

我们两清 提交于 2019-12-11 05:23:16
问题 I am trying to read a few text lines from a file in matlab. Using the regexp function to extract some named tokens. While everything works quite nice in octave I cannot get the same expression to work in Matlab. There are different kinds of lines i want to process, like: line1 = 'attr enabled True'; line2 = 'attr width 1.2'; line3 = 'attr size 8Byte'; The regular expression I have come up with looks like: pattern = '^attr +(?<name>\S+) +(?:(?<number>[+-]?\d+(?:\.\d+)?)(?<unit>[a-z,A-z]*)?|(?