regex

RegEx - find a word inside a specific section of a file

隐身守侯 提交于 2021-01-28 06:26:29
问题 I am trying to set up an alarm in a piece of weather software to look at a forecast for my area and tell me if the word "severe" appears in the upcoming forecast. I am looking at the following text file (shortened down a bit): 000 FPUS55 KBOU 301529 ZFPBOU Zone Forecast Product for Northeast Colorado National Weather Service Denver/Boulder CO 929 AM MDT Sat Jun 30 2018 COZ042-044-010615- Northeast Weld County-Morgan County- including Briggsdale, Grover, Pawnee Buttes, Raymer, Stoneham, Brush,

Keep elements with pattern in pandas series without converting them to list

让人想犯罪 __ 提交于 2021-01-28 06:25:35
问题 I have the following dataframe: df = pd.DataFrame(["Air type:1, Space kind:2, water", "something, Space blu:3, somethingelse"], columns = ['A']) and I want to create a new column that contains for each row all the elements that have a ":" in them. So for example in the first row I want to return "type:1, kind:2" and for the second row I want "blu:3". I managed by using a list comprehension in the following way: df['new'] = [[y for y in x if ":" in y] for x in df['A'].str.split(",")] But my

Removing spaces between numbers separated by comma

纵饮孤独 提交于 2021-01-28 06:25:02
问题 I would like to remove any space between numbers separated by "." or "," for example: 10 , 45, 3 should be: 10,45,3 and 10 . 45 . 3 should be: 10.45.3 Any help to do that in regular expressions ? 回答1: Using /(\d)\s*([,.])\s*(\d)/g, "$1$2$3" you should be able to do that var str = "Operations and maintenance $258 .277 billion , Military Personnel $153 .531 billion ,Procurement $97, 757 billion. Research, Development, Testing & Evaluation $63 . 347 billion, Military Construction $8 , 069

Regex, everything between two characters except escaped characters

六月ゝ 毕业季﹏ 提交于 2021-01-28 06:13:07
问题 I've tried searching extensively for this, and there are similar problems but yet I haven't been able to figure this out. My problem is that I have, among others, strings on this form: %Aliquam hendrerit mollis pretium! Praesent id% %molestie \*libero vel\%\% pulvinar? Sed% \%% urna. \% Fusce% in *sapien %mau\*ris.% I want to select everything between two %s, ignoring cases where characters are preceeded by a \. The first one is trivial, and I have somehow been able to do the second one. The

RegEx get last match of a date format from string inside a Google Sheets cell

白昼怎懂夜的黑 提交于 2021-01-28 06:01:56
问题 My objective is to extract a date string and following characters using Regex in Google Sheets (sheets function: regexextract) where the string is the last line of a cell and starts with a date format "yyyy-DD-MM" followed by ":". So the RegExpression that I currently have looks like: \d{4}-\d{2}-\d{2}:.+ This works fine but it returns the first match. Instead I want to start at the end of the cell and extract the last match when there are multiple date strings. This is because the contents

Perl one-liner, printing filename as part of output

做~自己de王妃 提交于 2021-01-28 05:52:35
问题 I posted a question a month or so ago about how to print out a listing of files and all occurrences of a regular expression in those files. The aim being to get a file like this: file1 A12345 file2 A12399 file2 A12599 file3 A11223 and so on. After some help from Miller and anttix (thanks again!), the expression wound up being: perl -lne 'print "$ARGV $1" while(/\<myxmltag>(..............)<\/myxmltag>/g)' *.XML > /home/myuser/myfiles.txt Now I'd really like to be able to add the file's create

How to split a binary string into groups that containt only ones or zeros with Java regular expressions? [duplicate]

谁都会走 提交于 2021-01-28 05:44:10
问题 This question already has an answer here : Split regex to extract Strings of contiguous characters (1 answer) Closed 5 years ago . I'm new to using regular expressions, but I think that in an instance like this using them would be the quickest and most ellegant way. I have a binary string, and I need to split it into groups that only contain consecutive zeros or ones, for example: 110001 would be split into 11 000 1 I just can't figure it out, this is my current code, thanks: class Solution {

htaccess change url parameter

冷暖自知 提交于 2021-01-28 05:39:07
问题 I have a WP site which uses a calendaring plugin - currently the url the calendar system creates to change the month view of the calendar is hitting a url which fails to advance the month view of the calendar... I have worked out what the correct url should be - but need a way of redirecting from the incorrect url to the correct one... So... The incorrect url is: /calendar/?date=2018-04 The correct url is /calendar/?tribe-bar-date=2018-04 So, I am basically looking for a way to redirect /

Java regex pattern too long? [closed]

对着背影说爱祢 提交于 2021-01-28 05:31:49
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question I have this regex which is a bit longer than usual. I try to capture some values in a text document. \\n*.*(k\\s=\\s\\d)(.|\\n)*?estimate\\s.*\\n*\\s*((\\d+|<)\\.\\d+)\\s*((\\d+|<)\\.\\d+)\\s*((\\d+|<)\\.\\d+)\\s*((\\d+|<)\\.\\d+)\\s*((\\d+|<)\\.\\d+)\\s*((\\d+|<)\\.\\d+)\\s+ It

Python regex “OR” gives empty string when using findall

余生长醉 提交于 2021-01-28 05:21:31
问题 I'm using a simple regex (.*?)(\d+[.]\d+)|(.*?)(\d+) to match int/float/double value in a string. When doing findall the regex shows empty strings in the output. The empty strings gets removed when I remove the | operator and do an individual match. I had also tried this on regex101 it doesn't show any empty string. How can I remove this empty strings ? Here's my code: >>>import re >>>match_float = re.compile('(.*?)(\d+[.]\d+)|(.*?)(\d+)') >>>match_float.findall("CA$1.90") >>>match_float