regex

Match unescaped quotes in quoted csv

空扰寡人 提交于 2021-02-07 07:38:59
问题 I've looked at several of the Stack Overflow posts with similar titles, and none of the accepted answers have done the trick for me. I have a CSV file where each "cell" of data is delimited by a comma and is quoted (including numbers). Each line ends with a new line character. Some text "cells" have quotation marks in them, and I want to use regex to find these, so that I can escape them properly. Example line: "0","0.23432","234.232342","data here dsfsd hfsdf","3/1/2016",,"etc","E 60"","AD"8

Use of findall and parenthesis in Python

浪尽此生 提交于 2021-02-07 07:31:12
问题 I need to extract all letters after the + sign or at the beginning of a string like this: formula = "X+BC+DAF" I tried so, and I do not want to see the + sign in the result. I wish see only ['X', 'B', 'D'] . >>> re.findall("^[A-Z]|[+][A-Z]", formula) ['X', '+B', '+D'] When I grouped with parenthesis, I got this strange result: re.findall("^([A-Z])|[+]([A-Z])", formula) [('X', ''), ('', 'B'), ('', 'D')] Why it created tuples when I try to group ? How to write the regexp directly such that it

Use of findall and parenthesis in Python

别等时光非礼了梦想. 提交于 2021-02-07 07:31:01
问题 I need to extract all letters after the + sign or at the beginning of a string like this: formula = "X+BC+DAF" I tried so, and I do not want to see the + sign in the result. I wish see only ['X', 'B', 'D'] . >>> re.findall("^[A-Z]|[+][A-Z]", formula) ['X', '+B', '+D'] When I grouped with parenthesis, I got this strange result: re.findall("^([A-Z])|[+]([A-Z])", formula) [('X', ''), ('', 'B'), ('', 'D')] Why it created tuples when I try to group ? How to write the regexp directly such that it

What does the regex pattern 'pL' do? [duplicate]

心已入冬 提交于 2021-02-07 07:22:20
问题 This question already has answers here : What is the {L} Unicode category? (2 answers) Closed 2 years ago . There is a common Regex used to slugify urls ~[^\\pL\d]+~u but what does the \\pL in the first preg_replace() mean? Here are some examples: How can I replace ":" with "/" in slugify function? http://snipplr.com/view/22741/slugify-a-string-in-php/ http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php http://www.daniweb.com/web-development/php/threads/471380/php

Sequentially replace multiple places matching single pattern in a string with different replacements

不问归期 提交于 2021-02-07 07:12:16
问题 Using stringr package, it is easy to perform regex replacement in a vectorized manner. Question: How can I do the following: Replace every word in hello,world??your,make|[]world,hello,pos to different replacements, e.g. increasing numbers 1,2??3,4|[]5,6,7 Note that simple separators cannot be assumed, the practical use case is more complicated. stringr::str_replace_all does not seem to work because it str_replace_all(x, "(\\w+)", 1:7) produces a vector for each replacement applied to all

Sequentially replace multiple places matching single pattern in a string with different replacements

爷,独闯天下 提交于 2021-02-07 07:10:00
问题 Using stringr package, it is easy to perform regex replacement in a vectorized manner. Question: How can I do the following: Replace every word in hello,world??your,make|[]world,hello,pos to different replacements, e.g. increasing numbers 1,2??3,4|[]5,6,7 Note that simple separators cannot be assumed, the practical use case is more complicated. stringr::str_replace_all does not seem to work because it str_replace_all(x, "(\\w+)", 1:7) produces a vector for each replacement applied to all

remove everything after the last underscore of a column in R [duplicate]

时光怂恿深爱的人放手 提交于 2021-02-07 06:55:47
问题 This question already has answers here : R regex find last occurrence of delimiter (4 answers) Closed 4 years ago . I have a dataframe and for a particular column I want to strip out everything after the last underscore. So: test <- data.frame(label=c('test_test_test', 'test_tom_cat', 'tset_eat_food', 'tisk - tisk'), stuff=c('blah', 'blag', 'gah', 'nah') , numbers=c(1,2,3, 4)) should become result <- data.frame(label=c('test_test', 'test_tom', 'tset_eat', 'tisk - tisk'), stuff=c('blah', 'blag

PHP: remove extra space from a string using regex

独自空忆成欢 提交于 2021-02-07 06:29:05
问题 How do I remove extra spaces at the end of a string using regex (preg_replace)? $string = "some random text with extra spaces at the end "; 回答1: There is no need of regex here and you can use rtrim for it, its cleaner and faster: $str = rtrim($str); But if you want a regex based solution you can use: $str = preg_replace('/\s*$/','',$str); The regex used is /\s*$/ \s is short for any white space char, which includes space. * is the quantifier for zero or more $ is the end anchor Basically we

Hive RegexSerDe Multiline Log matching

陌路散爱 提交于 2021-02-07 05:52:33
问题 I am looking for a regex that can be fed to a "create external table" statement of Hive QL in the form of "input.regex"="the regex goes here" The condition is that the logs in the files that the RegexSerDe must be reading are of the following form: 2013-02-12 12:03:22,323 [DEBUG] 2636hd3e-432g-dfg3-dwq3-y4dsfq3ew91b Some message that can contain any special character, including linebreaks. This one does not have a linebreak. It just has spaces on the same line. 2013-02-12 12:03:24,527 [DEBUG]

Hive RegexSerDe Multiline Log matching

末鹿安然 提交于 2021-02-07 05:52:12
问题 I am looking for a regex that can be fed to a "create external table" statement of Hive QL in the form of "input.regex"="the regex goes here" The condition is that the logs in the files that the RegexSerDe must be reading are of the following form: 2013-02-12 12:03:22,323 [DEBUG] 2636hd3e-432g-dfg3-dwq3-y4dsfq3ew91b Some message that can contain any special character, including linebreaks. This one does not have a linebreak. It just has spaces on the same line. 2013-02-12 12:03:24,527 [DEBUG]