w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
regex to match space but escaped space
For the second case you can use: (?<!\) Edit: I don't usually work with javascript so i don't know of any quick shortcut, so i think you can do this at two steps: Perform a substitution (replace) using this regex: \s, replace with semicolon ; like this: var newCommand = command0.replace(/\s/g, ";"); Then perform split using this regex: s like this: var result = newCommand.split(/s/);

Categories : Javascript

Regex to match a doubles separated by one space only
You can use this: ^-(?:d+[.]d+(?:[ ]d+[.]d+)*)?$ Explanation: ^ - // Match '-' (?: // An optional non-capturing group d+[.]d+ // Match pattern - 14.45 (?: // A 0 or more times repeating Non-capture group [ ] // A space d+[.]d+ // Pattern matching - 14.56 )* )? $

Categories : C#

Regex to match space separated words like CSS classes
You are probably looking for something like: (^|s)name(s|$) starting at the beginning of the string (^) or after whitespace ending at the end of the string ($) or before whitespace See e.g. http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

Categories : Regex

Python Regex on comma, space
Your first case doesn't even need a regex. You can simply do: "Dogs,Cats".split(",") For your 2nd case, you can use: re.split(r',s*', "Dogs, Cats")

Categories : Python

Python Regex for Words & single space
Try if the following works. It matches both groups of characters to remove, but only when there is at least an space in them subsitutes it with an space. import re list_of_strings = ["3He2l2lo Wo45rld!", "Hello World- -number two-", "Hello World number .. three"] for str in list_of_strings: print(re.sub(r'((?:[^A-Za-zs]|s)+)', lambda x: ' ' if ' ' in x.group(0) else '' , str)) It yields: Hello World Hello World number two Hello World number three

Categories : Python

Getting rid of an optional space in Python regex script
Instead of rewriting your regular expression, you can always just strip() the whitespace: >>> L = [u' John 3:16', u' John 2', u'1 Kings 4', u' Romans 4'] >>> print map(unicode.strip, L) [u'John 3:16', u'John 2', u'1 Kings 4', u'Romans 4'] map() here is just identical to: >>> print [i.strip() for i in L] [u'John 3:16', u'John 2', u'1 Kings 4', u'Romans 4']

Categories : Python

Regex - match either word/digit or only space within a single word
I'd remove s from the character class and use * delimiter: ([a-zA-Z0-9_.,!""'/$-]*) and you can simplify: ([w.,!""'/$-]*)

Categories : Dotnet

Python 3 Regex Last Match
Description This regex will match the string value XX which can be replaced with the user input. The regex will also require that the XX string be surrounded by white space or at the beginning of your sample text which prevents the accidental edge case where XX is found inside a word like EXXON. (?<=s|^)(xx)s.*?s(d+)(?=s|$) Code Example: I don't know python well enough to offer a proper python example, so I'm including a PHP example to simply show how the regex would work and the captured groups <?php $sourcestring="EXXON abcd XX blah blah 123 more blah blah"; preg_match('/(?<=s|^)(xx)s.*?s(d+)(?=s|$)/im',$sourcestring,$matches); echo "<pre>".print_r($matches,true); ?> $matches Array: ( [0] => XX blah blah 123 [1] => XX [2] => 123 )

Categories : Python

Creating a match with regex in Python
If you always want to gather the price, you can do this: regex_string = r'= (.*? per contract)' This catches: '625 dollars per contract' All it does is take anything between the equal sign (and space after it) and the words "per contract." Since your regex assumes that the words "per contract" will always be present, so does mine. If you just want the price, you can do this instead: >>>regex_string = r'= (.*?) per contract' >>>matchobj = re.search(regex_string, "(.0025 = 625 dollars per contract)") >>>matchobj.groups() ('625 dollars',)

Categories : Python

How to write a regex in python to match this?
You need to add the python regex for whitespace into your pattern to account for the newlines. Try this: regex = r"[1-9]+) .*s.*" s is the regex for any whitespace

Categories : Python

Python regex to match IP range
You can use this: re.compile(r"66.249.(?:6[4-9]|[78]d|9[0-5]).d{1,3}$") if you are motivated you can replace d{1,3} by : (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) Explanation: A regex engine doesn't know what a numeric range is. The only way to describe a range is to write all the possibilities with alternations: 6[4-9] | [78][0-9] | 9[0-5] 6 can be followed by 4 to 9 --> 64 to 69 7 or 8 can be followed by 0 to 9 --> 70 to 89 9 can be followed by 0 to 5 --> 90 to 95

Categories : Python

Python regex re.match() not returning any results
Regular expressions are used when you want a "fuzzy" match - that is, you aren't sure if the string you are looking for will be identical every time. In this case, the string you are looking for appears to be exactly -----BEGIN PGP MESSAGE----. In this case, the string.find function will be simpler to use and faster to boot. >>> a = "This is a PGP encrypted email. -----BEGIN PGP MESSAGE----- !@#$%^..." >>> b = "This is not encrypted. My hovercraft is full of eels." #example strings >>> a.find("-----BEGIN PGP MESSAGE-----") 30 # Return value '30' means that the search string was found at index 30 of source string >>> b.find("-----BEGIN PGP MESSAGE-----") -1 # -1 means 'not found in the source string' >>>

Categories : Python

Python regex to match a specific word
You should use re.search here not re.match. From the docs on re.match: If you want to locate a match anywhere in string, use search() instead. If you're looking for the exact word 'Not Ok' then use  word boundaries, otherwise if you're only looking for a substring 'Not Ok' then use simple : if 'Not Ok' in string. >>> strs = 'Test result 1: Not Ok -31.08' >>> re.search(r'Not Ok',strs).group(0) 'Not Ok' >>> match = re.search(r'Not Ok',strs) >>> if match: ... print "Found" ... else: ... print "Not Found" ... Found

Categories : Python

Match the folder list by using regex in python
IDd+_d+_d+ Matches the ID followed by three groups of one or more digits, separated by underscore. And the Python code: > import re > str = "https://10.0.4.3/myrepos/Projects/ID87_070_138" > print re.findall(r"IDd+_d+_d+", str) With the result: ['ID87_070_138']

Categories : Python

how do i return a string from a regex match in python
You should use re.MatchObject.group(0). Like imtag = re.match(r'<img.*?>', line).group(0) Edit: You also might be better off doing something like imgtag = re.match(r'<img.*?>',line) if imtag: print("yo it's a {}".format(imgtag.group(0))) to eliminate all the Nones.

Categories : Python

Python regex to match multiple times
You've got extra /'s in the regex. In python the pattern should just be a string. e.g. instead of this: pattern = re.compile('/review: (http://url.com/(d+)s?)+/', re.IGNORECASE) It should be: pattern = re.compile('review: (http://url.com/(d+)s?)+', re.IGNORECASE) Also typically in python you'd actually use a "raw" string like this: pattern = re.compile(r'review: (http://url.com/(d+)s?)+', re.IGNORECASE) The extra r on the front of the string saves you from having to do lots of backslash escaping etc.

Categories : Python

Python regex to match 2 distinct delimiters
If I understand your needs correctly, you could use this: [[(?:(?<uid>w+)::)?(?!.*::)(?<page>[^| fv]+)(?:|(?<alias>[^| fv]+))?]] ^^^^^^^^ See here for a demo. I added a negative lookahead after the uid capture. I have given names to the captured groups but if you don't want them, that's the one without named captured groups: [[(?:(w+)::)?(?!.*::)([^| fv]+)(?:|([^| fv]+))?]]

Categories : Python

Match to string length by using regex in python
Although it is not clear which 1 or 2 length character strings you want to accept I propose the following regex: regex = re.compile("^[a-zA-Z][a-zA-Z0-9.-]{0,28}[a-zA-Z0-9]$") As the middle set includes all other this will directly match all words with length 3-30 as you wish. I hope this regex also matches your 2 length strings (I just assumed that the first character must be a letter), you need to add something (using '|') for single letter matches.

Categories : Python

Optional Ignore White Space in String (from Char set) Regex Python
Try the following: new_string = re.sub(r'w[w ]*w|w', "replace", original_string) w is equivalent to [a-zA-Z0-9_], so [w ] will match word characters, tabs, and spaces. So this regex means "match a word character, followed by any number of word characters or whitespace characters, followed by a word character, OR match a single word character". This way you will match whitespace between words but not the whitespace before or after words.

Categories : Python

Python regex: how to match strings that DO NOT contain an *exact* sentence?
Use a negative lookahead assertion like this: re.findall("(?!^.*This is message 12345. Ignore..*$).*", data) and also enable the m modifier, so that ^ and $ match the start and the end of a row.

Categories : Python

regex match all words in a python list not preeced by @
You could simply use a negative look-behind. A pattern like this should work: (?<!@)w+ Note the  (word boundaries) are there to ensure that it matches the whole word—without them it would match pples and uava.

Categories : Python

Python regex to match character a number of times
try with this kind of pattern (for 10 between 0 or 2 times): ^(([^1]+|1+(?=0))*10){0,2}([^1]+|1+(?=0))*$ You can easily adapt it for rabbit between 0 and 3 times: ^(([^r]+|r+(?=abbit))*rabbit){0,3}([^r]+|r+(?=abbit))*$

Categories : Python

Python Regex Match for every single character in a "alphanumeric word"
You can use this regex that follows your description list: (?i)[dptu][a-z0-9]{3}[a-z][0-9]{5}[a-z]{4} (?i) is a modifier to make the pattern case insensitive

Categories : Regex

Python Regex: Question mark (?) doesn't match in middle of string
Regex d? simply means that it should optionally (?) match single digit (d). If you use something like this, it will work as you expect (match single digit anywhere in the string): d

Categories : Python

javascript regex replace all doublequotes in string unless the doublequote is followed by space or comma space
A way: rebuild the json string: var str = '{"description":"This is my 12" pizza I ordered.","value":"1"}'; var regex = /"(.*?)"(?=s*([,:])s*"|(}))/g; var result = '{'; var arr = regex.exec(str); while (arr != null) { result += '"' + arr[1].replace(/\?"/g, '\"') + '"'; if (arr[2]) result += arr[2]; if (arr[3]) result += arr[3]; arr = regex.exec(str); } console.log(result);

Categories : Javascript

Regex to match paths that don't match a specific pattern: Express Router
The following regex will match any path except those starting with /foo/ app.get(/^/([^f][^o][^o]|.{1,2}|.{4,})/.*$/, routes.index); I assume that this is a standard javascript regex.

Categories : Regex

Regex to match single new line. Regex to match double new line
To match exactly N repetitions of the same character you need lookaheads and lookbehinds (see Match exactly N repetitions of the same character). Since javascript doesn't support the latter, a pure regexp solution seems to be impossible. You'll have to use a helper function, for example: > x = "...a...aa...aaa...aaaa...a...aa" "...a...aa...aaa...aaaa...a...aa" > x.replace(/a+/g, function($0) { return $0.length == 2 ? '@@' : $0; }) "...a...@@...aaa...aaaa...a...@@"

Categories : Javascript

Regex to match only till first occurence of class match
You were missing ? Your regex would be (?i)(.*?)case[^a-zd]*(d+)(.*) You can toggle case insensitive match using (?i) in regex

Categories : Regex

Regex - Find the match that is inside a match
You can try this regex: /href=[^>]+.pdf/ regex101 demo Most of the time, when you can avoid .* or .+ (or their lazy versions), it's better :) Also, don't forget to escape periods.

Categories : PHP

Regex that match if the match contains special word
You're kind of on the right track with lookahead assertions: {{START}}(?:(?!{{END}})[sS])*specialword(?:(?!{{END}})[sS])*{{END}} Explanation: {{START}} # Match {{START}} (?: # Match... (?!{{END}}) # ...as long as we haven't reached {{END}} yet: [sS] # any character )* # any number of times. specialword # Match "specialword" (?: # Match (as before)... (?!{{END}}) # whatever follows, unless it's {{END}} [sS] )* {{END}} # Then finally match {{END}}

Categories : Regex

Java regex: need one regex to match all the formats specified
Try using a reluctant quantifier: _year:.*?s. .replaceAll("_year:.*?\s", "_year:Y ") System.out .println("utc-hour_of_year:2013-07-30T17 dsfsdgfsgf utc-week_of_year:2013-W31 dsfsdgfsdgf" .replaceAll("_year:.*?\s", "_year:Y ")); utc-hour_of_year:Y dsfsdgfsgf utc-week_of_year:Y dsfsdgfsdgf

Categories : Java

Regex.Match() won't match a substring
Try removing ^ and $: Regex regex = new Regex(@"[ABCEGHJKLMNPRSTVXY]{1}d{1}[A-Z]{1} *d{1}[A-Z]{1}d{1}", RegexOptions.None); ^ : The match must start at the beginning of the string or line. $ : The match must occur at the end of the string or before at the end of the line or string. If you want to match only in word boundaries you can use  as suggested by Mike Strobel: Regex regex = new Regex(@"[ABCEGHJKLMNPRSTVXY]{1}d{1}[A-Z]{1} *d{1}[A-Z]{1}d{1}", RegexOptions.None);

Categories : C#

regex not returning match but there is clearly a match
You need to escape the dollar sign. start = '>$' end = '</td>' AnnualDiv = re.search('%s(.*)%s' % (start, end), s).group(1) The reason is that the $ is a special character in regex. (It matches the end of a string or before the newline.) This will set AnnualDiv to the string '0.48'. If you want to add the $, you can do it using this: AnnualDiv = "$%s" % re.search('%s(.*)%s' % (start, end), s).group(1)

Categories : Python

Javascript regex to match a regex
A regular expression to match a regular expression is //((?![*+?])(?:[^ [/\]|\.|[(?:[^ ]\]|\.)*])+)/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/ To break it down, / matches a literal / (?![*+?]) is necessary because /* starts a comment, not a regular expression. [^ [/\] matches any non-escape sequence character and non-start of character group [...] matches a character group which can contain an un-escaped /. \. matches a prefix of an escape sequence + is necessary because // is a line comment, not a regular expression. (?:g...)? matches any combination of non-repeating regular expression flags. So ugly. This doesn't attempt to pair parentheses, or check that repetition modifiers are not applied to themselves, but filters out most of the other ways that regular expressions

Categories : Javascript

Regex- Space or no space
"space or no space" is the same as "zero or one space", or perhaps "zero or more spaces", I'm not sure exactly what you want. In the following discussion, I'm going to use <space> to represent a single space, since a single space is hard to see in short code snippets. In the actual regular expression, you must use an actual space character. zero-or-one-space is represented as a single space followed by a question mark (<space>?). That will match exactly zero or one spaces. If you want to match zero or any number of spaces, replace the ? with * (eg: <space>*) If by "space" you actually mean "any whitespace character" (for example, a tab), you can use s which most regular expression engines translate as whitespace. So, zero-or-one of any whitespace character would be s?,

Categories : Regex

White space in awk print and match
This should do the trick: awk 'NR==2 {gsub(/;/,""\);print (match($3,/^ch/\) ? " ":""\),$2,$4}' You need to use a comma to separate the output with the OFS (output field separator) in awk which by default is a single space. Without the comma you're doing string concatenation.

Categories : Regex

Looking for non-zero property TOs: Can I match a Description with number property, but use a regex match?
It is known that integer types has to be passed as integers in the description rendering the usage of regular expressions useless unfortunately. I do not have a QTP installation at hand right now, but to investigate it further, what happens if you use Print Browser("myBrowser").WebElement("height:=11").ChildObjects.Count and Print Browser("myBrowser").WebElement("height:=^[1-9][0-9]*$").ChildObjects.Count Where "myBrowser" is your browser definition of course.

Categories : Regex

regex, space between works only
Try using this pattern: /^[a-zA-Z]+( [a-zA-Z]+)*$/ This will match any sequence words (of Latin letters) separated by a single space, but with no spaces on the end. You can also simplify this a little bit by using the i flag for case insensitive matching: /^[a-z]+( [a-z]+)*$/i

Categories : Javascript

regex exclude space from W
Ah, so you don't need to catch the results of the match - just to test whether or not the string matches some pattern. That can be done with... $pattern = '/^[A-Z0-9](?:[A-Z0-9 ]*[A-Z0-9])?$/i'; ... but that's destined to fail if you want to cover letters outside of ASCII range. You should use this instead then: $pattern = '/^[p{L}0-9](?:[p{L}0-9 ]*[p{L}0-9])?$/u'; Check the demo to see that in action.

Categories : PHP

How can I make no line space using regex?
Thanks for clearing up your question: while (richTextBox1.Text.Contains(" ")) richTextBox1.Text = richTextBox1.Text.Replace(" ", " "); string[] linesafter = richTextBox1.Lines; for (int i = 0; i < richTextBox1.Lines.Length; i++) if (richTextBox1.Lines[i].EndsWith(";")) linesafter[i] = linesafter[i] + " "; richTextBox1.Lines = linesafter;

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.