regex

basic_regex throws bad_cast with char32_t

北城余情 提交于 2021-02-11 06:51:07
问题 Why does the following code generate std::bad_cast exception? #include <iostream> #include <regex> #include <string> int main() { std::basic_string<char32_t> reg = U"^\\w"; try { std::basic_regex<char32_t> tagRegex(reg); } catch(std::exception &e) { std::cout << e.what() << std::endl; } return 0; } This sample on Ideone for convenience: https://ideone.com/Saea88 Using char or wchar instead of char32_t runs without throwing though (proof: https://ideone.com/OBlXed). 回答1: You can find here:

Creating a dataframe with text from a website

核能气质少年 提交于 2021-02-11 06:38:10
问题 I've been asked to create a data frame in R using information copied from a website; the data is not contained in a file. The full data list is at: https://www.npr.org/2012/12/07/166400760/hollywood-heights-the-ups-downs-and-in-betweens Here is a portion of the data: Leading Men (Average American male: 5 feet 9.5 inches) Dolph Lundgren — 6 feet 5 inches John Cleese — 6 feet 5 inches Michael Clarke Duncan — 6 feet 5 inches Vince Vaughn — 6 feet 5 inches Clint Eastwood — 6 feet 4 inches Jimmy

How to add information found with regular expressions in a CSV file

眉间皱痕 提交于 2021-02-11 06:32:45
问题 I am trying to "append" new information to a CSV file. The problem is that that information is not in a dataframe structure, but is information extracted from a text using regular expressions. The sample text would be the next one: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id diam posuere, eleifend diam at, condimentum justo. Pellentesque mollis a diam id consequat. TITLE-SDFSD-DFDS-SFDS-01-01: This is the title 1 that is split into two lines with a blank line in the

How to add information found with regular expressions in a CSV file

被刻印的时光 ゝ 提交于 2021-02-11 06:31:28
问题 I am trying to "append" new information to a CSV file. The problem is that that information is not in a dataframe structure, but is information extracted from a text using regular expressions. The sample text would be the next one: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id diam posuere, eleifend diam at, condimentum justo. Pellentesque mollis a diam id consequat. TITLE-SDFSD-DFDS-SFDS-01-01: This is the title 1 that is split into two lines with a blank line in the

How to add information found with regular expressions in a CSV file

随声附和 提交于 2021-02-11 06:31:27
问题 I am trying to "append" new information to a CSV file. The problem is that that information is not in a dataframe structure, but is information extracted from a text using regular expressions. The sample text would be the next one: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id diam posuere, eleifend diam at, condimentum justo. Pellentesque mollis a diam id consequat. TITLE-SDFSD-DFDS-SFDS-01-01: This is the title 1 that is split into two lines with a blank line in the

Replace URL segment hyphens with spaces using htaccess rewrite rules

杀马特。学长 韩版系。学妹 提交于 2021-02-11 06:19:44
问题 I have a friendly URL as follows: www.dominio.com.br/cidade/sao-paulo And here's my htaccess rewrite rule: RewriteRule ^cidade/(.*)$ busca-cidade.php?cidade=$1 And the SQL query: Select * from cidades where cidade = 'sao-paulo' Is it possible to replace the hyphens with spaces using htaccess and rewrite rules? So the friendly URL will be mapped to: www.dominio.com.br/busca-cidade.php?cidade=sao%20paulo This finished my code, was great, would give to optimize. #################################

Compare two strings and Extract value of variable data in Python

风流意气都作罢 提交于 2021-02-11 06:16:41
问题 In my python script, I have a list of strings like, birth_year = ["my birth year is *","i born in *","i was born in *"] I want to compare one input sentence with the above list and need a birth year as output. The input sentence is like: Example1: My birth year is 1994. Example2: I born in 1995 The output will be: Example1: 1994 Example2: 1995 I applied many approaches by using regex. But I didn't find a perfect solution for the same. 回答1: If you change birth_year to a list of regexes you

Compare two strings and Extract value of variable data in Python

落爺英雄遲暮 提交于 2021-02-11 06:16:25
问题 In my python script, I have a list of strings like, birth_year = ["my birth year is *","i born in *","i was born in *"] I want to compare one input sentence with the above list and need a birth year as output. The input sentence is like: Example1: My birth year is 1994. Example2: I born in 1995 The output will be: Example1: 1994 Example2: 1995 I applied many approaches by using regex. But I didn't find a perfect solution for the same. 回答1: If you change birth_year to a list of regexes you

How validate decimal with optional percentage symbol using Regex?

纵然是瞬间 提交于 2021-02-11 05:28:18
问题 As the title of the question, I need to validate regex using the following values​​: (Maximum 2 decimal places, and 9 integers) with an optional percent symbol. Valid: 10% 0% 1111111.12% 15.2% 10 2.3 Invalid: .% 12.% .02% % 123456789123.123 I tryed: ^[0-9]{0,9}([\.][0-9]{0,2})\d[\%]{0,1}?$ But It does not work as I want. 回答1: try this ^\d{1,9}(\.\d{1,2})?%?$ I tested over rubular and it is ok for your set of example. 回答2: Try this: ^[0-9]{1,9}([\.][0-9]{1,2})?[\%]?$ 来源: https://stackoverflow

escaping \n in \s match in reg ex python

白昼怎懂夜的黑 提交于 2021-02-11 04:49:08
问题 I want to substitute all space characters (except \n ) with "" . I tried using regular expression with \s+ but it matches with newline character as well. Is there any method to skip \n in \s in regex? 回答1: If you do not have to think of Unicode, you could use [ \t\r\f\v] Or, since \v matches a VT (verical symbol, \x0b ), \r is also considered a line break, and \f is also a kind of a vertical whitespace (rather obsolete now though - (form feed, \x0c ): [ \t] See docs: \s When the UNICODE flag