regex

Add a new line after a matched pattern in Notepad++

…衆ロ難τιáo~ 提交于 2021-02-02 09:52:40
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true

Add a new line after a matched pattern in Notepad++

痴心易碎 提交于 2021-02-02 09:50:46
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true

Add a new line after a matched pattern in Notepad++

本秂侑毒 提交于 2021-02-02 09:50:09
问题 I have a csv-file, now i need to bring it in another form. I want to have a line break \r\n after a specific pattern. All patterns look like this: true or false; int number between 0 and 100; decimal number with two or three digits after the point; true or false; For example: false;2;23.987;false; true;0;8.37;false; false;8;166.987;false; and after the last semicolon, i want to have a line break. I am using notepad++. Thanks for your help 回答1: You may use \b(?:true|false);\d+;\d+\.\d+;(?:true

pandas.replace conflict with str.replace regex. Code Order

試著忘記壹切 提交于 2021-02-02 09:47:33
问题 My task is to remove any content in a parenthesis and remove any numbers followed by Country name. Change the names of a couple of countries. e.g. Bolivia (Plurinational State of)' should be 'Bolivia' Switzerland17' should be 'Switzerland'`. My original code was in the order: dict1 = { "Republic of Korea": "South Korea", "United States of America": "United States", "United Kingdom of Great Britain and Northern Ireland": "United Kingdom", "China, Hong Kong Special Administrative Region": "Hong

Can't use ^ to say “all but”

给你一囗甜甜゛ 提交于 2021-02-02 09:45:44
问题 I have a text in which I want to get only the hexadecimal codes. Like: "thisissometextthisistext\x64\x6f\x6e\x74\x74\x72\x61\x6e\x73\x6c\x61\x74\x65somemoretextoverhere" It's possible to get the hex codes with \x.. But it doesn't seems I can do something like (^\x..) to select everything but the hex codes. Any workarounds? 回答1: You may use a (?s)((?:\\x[a-fA-F0-9]{2})+)|. regex (that will match and capture into Group 1 any 1+ sequences of hex values OR will just match any other char including

regex to match a username with no consecutive spaces

ぃ、小莉子 提交于 2021-02-02 09:37:58
问题 I am struggling to make a javascript regex to satisfy the following: The first character has to be alphabetical ( [a-zA-Z] ) The rest can be any letters, any numbers, hyphen, dot, underscore and spaces BUT no consecutive spaces, e.g: two or more spaces in a row The length has to be between 3 and 25 (inclusive) So here is what I found Regex: /^[a-z][\s\w.-]{3,24}$/i My current regex works, but won't be able to test whether the user has written consecutive spaces. How can I test for that? 回答1:

regex to match a username with no consecutive spaces

◇◆丶佛笑我妖孽 提交于 2021-02-02 09:33:29
问题 I am struggling to make a javascript regex to satisfy the following: The first character has to be alphabetical ( [a-zA-Z] ) The rest can be any letters, any numbers, hyphen, dot, underscore and spaces BUT no consecutive spaces, e.g: two or more spaces in a row The length has to be between 3 and 25 (inclusive) So here is what I found Regex: /^[a-z][\s\w.-]{3,24}$/i My current regex works, but won't be able to test whether the user has written consecutive spaces. How can I test for that? 回答1:

python : pass regex back-reference value to method

折月煮酒 提交于 2021-02-02 09:31:12
问题 I have this content: Data1 import filename.in Data2 and want to replace import filename.in line with the content of filename file, so I use this: content = re.sub(r'import\s+(.*)\s+\n', '\n' + read_file('\1') + '\n', content) read_file(in) returns the content of file in . def read_file(file): with open(file) as f: return f.read() the problem is that back-ref \1 does not eval to filename.in : No such file or directory: '\\1' any suggestion? 回答1: read_file(..) is called not by the re.sub . '\1'

Python regex does not match line start

不羁岁月 提交于 2021-02-02 09:28:51
问题 I have a text file with some data: ... DATA_ARRAY Some[] = { ... }; and I have a python 2.7 regex like this: regx = re.compile("^DATA_ARRAY Some\[\].*?};", re.DOTALL) regmatch = re.search(regx, data) print regmatch.group(0) The problem is that the regex does not match anything (regmatch is None). If I remove the ^ then it matches just fine. What am I doing incorrectly here? I would like to add the line beginning search symbol. 回答1: ^ checks for start of the string.. add re.MULTILINE flag.

Why python regular expression (?P=name) doesn't work

℡╲_俬逩灬. 提交于 2021-02-02 09:27:06
问题 I am learning ' re ' part of Python, and the named pattern (?P=name) confused me, When I using re.sub() to make some exchange for digit and character, the patter ' (?P=name) ' doesn't work, but the pattern ' \N ' and ' \g<name> ' still make sense. Code below: [IN]print(re.sub(r'(?P<digit>\d{3})-(?P<char>\w{4})', r'(?P=char)-(?P=digit)', '123-abcd')) [OUT] (?P=char)-(?P=digit) [IN] print(re.sub(r'(?P<digit>\d{3})-(?P<char>\w{4})', r'\2-\1', '123-abcd')) [OUT] abcd-123 [IN] print(re.sub(r'(?P