regex

Powershell regex for string between two special characters

孤人 提交于 2021-02-05 08:08:34
问题 A file name as below $inpFiledev = "abc_XYZ.bak" I need only XYZ in a variable to do a compare with other file name. i tried below: [String]$findev = [regex]::match($inpFiledev ,'_*.').Value Write-Host $findev 回答1: Asterisks in regex don't behave in the same way as they do in filesystem listing commands. As it stands your regex is looking for underscore, repeated zero or more times, followed by any character (represented in regex by a period). So the regex finds zero underscores right at the

Powershell regex for string between two special characters

大憨熊 提交于 2021-02-05 08:08:10
问题 A file name as below $inpFiledev = "abc_XYZ.bak" I need only XYZ in a variable to do a compare with other file name. i tried below: [String]$findev = [regex]::match($inpFiledev ,'_*.').Value Write-Host $findev 回答1: Asterisks in regex don't behave in the same way as they do in filesystem listing commands. As it stands your regex is looking for underscore, repeated zero or more times, followed by any character (represented in regex by a period). So the regex finds zero underscores right at the

Regex to parse out a part of URL

假装没事ソ 提交于 2021-02-05 08:01:24
问题 I am having the following data, data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ I want to avoid the first http:// or https:// and check for the last '/' and parse out the remaining parts of the URL. But the challenge here is, we have '/' on the end of few URLs as well. The output which I want is,

How to match a string with an opening brace { in C++ regex

喜欢而已 提交于 2021-02-05 08:00:49
问题 I have about writing regexes in C++. I have 2 regexes which work fine in java. But these throws an error namely one of * + was not preceded by a valid regular expression C++ These regexes are as follows: regex r1("^[\s]*{[\s]*\n"); //Space followed by '{' then followed by spaces and '\n' regex r2("^[\s]*{[\s]*\/\/.*\n") // Space followed by '{' then by '//' and '\n' Can someone help me how to fix this error or re-write these regex in C++? 回答1: See basic_regex reference: By default, regex

Regex Skip space in match

≡放荡痞女 提交于 2021-02-05 08:00:45
问题 I have a string of digits that represent 3 different lenghts. I need to pick out the second length in the string but can't find away to exclude the white space from the match. Here is an example for the string. It has always 6 digits after the dot but before it vary. In this case it is 907.086614 that I need to match exactly. 1417.322835 907.086614 2.267717 ^\s(\d+\.\d{6}) I've played around with different look behind but can't get it to exclude the white space. 回答1: You can try this (?<=\s)(

Strange result of using asterisk * quantifier

南笙酒味 提交于 2021-02-05 08:00:32
问题 I am trying to practice asterisk * quantifier on a simple string, but while i have only two letters, the result contains a third match. <?php $x = 'ab'; preg_match_all("/a*/",$x,$m); echo '<pre>'; var_dump($m); echo '</pre>'; ?> the result came out: array(1) { [0]=> array(3) { [0]=> string(1) "a" [1]=> string(0) "" [2]=> string(0) "" } } As i understand it first matched a then nothing matched when b, so the result should be array(1) { [0]=> array(2) { [0]=> string(1) "a" [1]=> string(0) "" }

How to fetch data from MongoDB collection in C# using Regular Expression?

穿精又带淫゛_ 提交于 2021-02-05 08:00:31
问题 I am using MongoDB.Drivers nuget package in my MVC (C#) web application to communication with MongoDB database. Now, I want to fetch data based on specific column and it's value. I used below code to fetch data. var findValue = "John"; var clientTest1 = new MongoClient("mongodb://localhost:XXXXX"); var dbTest1 = clientTest1.GetDatabase("Temp_DB"); var empCollection = dbTest1.GetCollection<Employee>("Employee"); var builder1 = Builders<Employee>.Filter; var filter1 = builder1.Empty; var

How to make exceptions for certain words in regex

大憨熊 提交于 2021-02-05 08:00:10
问题 I'm very new in programming and regex so apologise if this's been asked before (I didn't find one, though). I want to use Python to summarise word frequencies in a literal text. Let's assume the text is formatted like Chapter 1 blah blah blah Chapter 2 blah blah blah .... Now I read the text as a string, and I want to use re.findall to get every word in this text, so my code is wordlist = re.findall(r'\b\w+\b', text) But the problem is that it matches all these Chapter s in each chapter title

Regular Expression to not allow 3 consecutive characters

佐手、 提交于 2021-02-05 07:56:47
问题 I have the following regex: Regex pattern = new Regex(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,20}/(.)$"); (?=.*\d) //should contain at least one digit (?=.*[a-z]) //should contain at least one lower case (?=.*[A-Z]) //should contain at least one upper case [a-zA-Z0-9]{8,20} //should contain at least 8 characters and maximum of 20 My problem is I also need to check if 3 consecutive characters are identical. Upon searching, I saw this solution: /(.)\1\1/ However, I can't make it to work

How to use regex lookahead and match the previous string / character class

℡╲_俬逩灬. 提交于 2021-02-05 07:56:07
问题 Trying to use negative look ahead to match a number if it doesn't precede a % sign. \d+(?!%) . 8989% . //matches 898, but not the 9% . I'd like it to match 8989 as a whole. Also is it possible use negative look ahead with matching a whole character class or more complex regex? [\d.+](?!%) . \d+(\.\d{1,2})?(?!%) . Which would match decimals not preceding a % 回答1: The \d+(?!%) pattern matches one or more digits, and grabs 8989 in 8989% at first, but the (?!%) negative lookahead fails that match