python,html,regex,wordpress,beautifulsoup
At least, you can rely on the tag names and text, navigating the DOM tree horizontally - going sideways. These are all strong, p and span (with id attribute set) tags you are showing. For example, you can get the strong text and get the following sibling: >>> from bs4...
I would try with: Pattern regex = Pattern.compile("(?<= )\\d(\\d*[,\\.]?\\d+)*(?=[ .]?sq)"); where: (?<= ) - there is space before \d - starts with digit (\d*[,\.]?\d+)* - next is digit or digits, there could be comma or point with more digits - and it can repeats like in 100,000,000 (?=[ .]?sq) -...
This matches and captures the empty string, followed by zero or more characters which are not captured: (?P<err>).* You want to move the .* inside the parentheses: (?P<err>.*) ...
It’s quite trivial: RegEx string.match(/\$((?:\d|\,)*\.?\d+)/g) || [] That || [] is for no matches: it gives an empty array rather than null. Matches $99 $.99 $9.99 $9,999 $9,999.99 Explanation / # Start RegEx \$ # $ (dollar sign) ( # Capturing group (this is what you’re looking for) (?: #...
Use a different set of delimiters for the regex. For example, you can write preg_match_all('~[^/\s]+/\S+\.(jpg|png|gif)~', $string, $results ...
As you mentioned you need to capture and replace the max value, I will take into account only that non-capturing group. The special character \s+ is used to indicate one or more white spaces. Regex reg = new Regex("(Movement\s+display_name=\"Movement\"\s+type=\".*\" .*min=\".*\"\s+max=\").*(\")"); Now you can replace the not captured group, I mean...
Just get the dot outside of the captruing group and then make it as optional. @"[+-]?\d+\.?\d*" Use anchors if necessary. @"^[+-]?\d+\.?\d*$" ...
Try following this var str='this is a pen. i am a boy'; var res= str.split(/[\.\!]+\s*|\n+\s*/); //this code return a array of sentense. alert(res); console.log(res); ...
java,regex,swing,jtable,tablecellrenderer
There's probably a better way, but basically, what this does it sets up a series of optional groups which allows a Pattern and Matcher to break the String down into "ranges" We then use those ranges to "inject" the rules... String text = "This is a example text background and...
This is one way to do it, using preg_match: $string ="SomeStringExample"; preg_match('/^[b-df-hj-np-tv-z]*/i', $string, $matches); $count = strlen($matches[0]); The regular expression matches zero or more (*) case-insensitive (/i) consonants [b-df-hj-np-tv-z] at the beginning (^) of the string and stores the matched content in the $matches array. Then it's just a matter...
return num = num.substring(1).replace(/,/g , " ").replace(".", ",") + " $"; Use this to English formatted num....
The quotes are an issue but not the issue you are running into when you escape them. Your delimiter is terminating your regex just before the closing a which is giving you the unknown modifier error. It appears you don't have error reporting on though so you aren't seeing that....
Test(?:1\d\d|200)\b You can simply use this.See demo. https://regex101.com/r/hI0qP0/26...
Instead of multiline flag you need single-line here. /\[FONT=(.*?)\](.*?)\[\/FONT\]/isg Single-line modifier makes dot symbol match newline characters as well - it is exactly your issue. Multiline modifier only makes beginning/end characters (^ and $) match start/end of line....
You are replacing even on "empty character", which is what * means at the end when there are 0 occurrences. Try to replace it with +, which means "one or more"...
You are trying to write a python code using ruby syntax. This is not a best approach to GTD. Slashes are handled right-to-left, yielding not what you expected. As soon as one finds herself putting three or more backslashes inside the string, she should admit, she’s doing it wrong. At...
You can use this: (?<=\d)\s+(?=\d|\-), using find and replace all in sublime text. (?<=\d) is a positive lookbehind, it checks if the previous symbol is a digit, without actually matching it. (?=\d) is a positive lookahead, same thing - checks if the following symbol is a digit, without actually matching...
Just put +, - inside a character class. sc1.useDelimiter("\\s*[-+]\\s*"); ...
Try using the unicode character code, \u2022, instead: message.replace(/\u2022/, "<br />\u2022"); ...
You could do this in a two step regex if you so desire: [^"]*"((?:[^\\"]|\\.)*)"\s*:\s*{(.*)} Your odd matches are your keys, and your even matches are your values. You'd need to run a secondary regex on your even matches to find all your values, something like: [^"]*"((?:[^\\"]|\\.)*)"\s*:\s*(?:true|false) Which should extract all...
You must be getting an error on the SET @dd line. You can't set values to any variable by assigning a statement. You have to use SELECT .... INTO ... syntax to set value for a variable. There are several other errors in your code. Change them as suggested below:...
python,regex,parsing,beautifulsoup,python-requests
In order to match the string with a literal backlash, you need to double-escape it in a raw string, e.g.: re.search(r'@CAD_DTA\\">(.+?)@[email protected]@CAD_LBL',result.text) ^ ^ In order to get the index of the found match, you can use start([group]) of re.MatchObject IDEONE demo: import re obj = re.search(r'@CAD_DTA\\">(.+?)@[email protected]@CAD_LBL', 'Some text [email protected]_DTA\\">I WANT...
You can use it with ssh and heredoc like this: ssh -t -t [email protected]<<'EOF' sed 's~out_prefix=orderid ^2\\\\d\\+ updatemtnotif/~out_prefix=orderid ^2\\\\d\\+ updatemtnotif_fr/~' ~/path/to/file exit EOF PS: It is important to quote the 'EOF' as shown....
You can probably use the str.count string method. A small example: In [25]: df Out[25]: Sentence bin_class 0 i wanna go to sleep. too late to take seroquel. 1 1 Adam and Juliana are leaving me for 43 days ta... 0 In [26]: df['Sentence'].str.count(pat='to') Out[26]: 0 3 1 0 Name:...
You can try: str = 'Chapter one'; str.match(/Chapter\s{1}(\w+)/); // or str.match(/Chapter (\w+)/); // or, for: thirty three etc str.match(/Chapter\s{1}(\w+(\s{1}\w+)?)/); Will return ["Chapter one", "one"]. Pattern description: /Chapter\s{1}(\w+)/ Chapter # will match only Chapter (case sensitive) \s{1} # one space (you can also use <space>) (\w+) # letter, at least one....
Could not figure out a regex solution, but here's a non-regex solution. It involves parsing numbers (not in curly braces) before each comma (unless its the last number in the string) and parsing strings (in curly braces) until the closing curly brace of the group is found. If regex solution...
I ended up with: $regexp = '/Nachricht\s-+\s+(.*?)\s+-+\sEnde/s'; So, it saves a few matching steps and does a bit of trimming on the message. More solid regexp.. it just works. Write a test to be on the safe side. \s - matches space -+ - matches one or more - chars...
python,regex,algorithm,python-2.7,datetime
What about fuzzyparsers: Sample inputs: jan 12, 2003 jan 5 2004-3-5 +34 -- 34 days in the future (relative to todays date) -4 -- 4 days in the past (relative to todays date) Example usage: >>> from fuzzyparsers import parse_date >>> parse_date('jun 17 2010') # my youngest son's birthday datetime.date(2010,...
Try this regex: (?<=[a-zA-Z])(\n) I used parentheses to capture the newline character. https://regex101.com/r/zS9pB4/3...
regex,python-2.7,regex-lookarounds
re.compile(ur"(?:^|(?<=[, ]))(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE) You can club 3 conditions using [] and |.See demo. https://regex101.com/r/vA8cB3/2#python...
You can make use of the multiline flag, and ^ and $ anchors that will match at the string start and string end repsectively: (?m)^.*lonfksa\.newsvine\.com.*$ Mind that you need to escape a dot in regex to make it match a literal dot. Your regex (?s)lonfksa.newsvine.com(?s) contains unescaped dots that match...
I don't understand why it would give me two hellos back? Because the first entry in the array is the overall match for the expression, which is then followed by the content of any capture groups the expression defines. Since the expression defines one capture group, you get back...
^\d{1,2}[A-Z]?(?:,\d{1,2}[A-Z]?)*$ Try this.See demo. https://regex101.com/r/hI0qP0/25...
Let's say the domain is as following String domain[] = { a, b, .., z, A, B, .. Z, 0, 1, 2, .. 9 }; Let's say the password size is 8 ArrayList allCombinations = getAllPossibleStrings2(domain,8); This is going to generate SIZE(domain) * LENGTH number of combinations, which is in...
To only allow digits, comma and spaces, you need to remove (, ) and -. Here is a way to do it with Matcher.find(): Pattern pattern = Pattern.compile("^[0-9, ]+$"); ... if (!m.find()) { evt.consume(); } And to allow an empty string, replace + with *: Pattern pattern = Pattern.compile("^[0-9, ]*$");...
SELECT regex_test_name FROM regex_test WHERE REGEXP_LIKE(regex_test_name, '([[:alpha:]])\1{3,9}') Inspired by dnoeth's answer, but since it catches the first character, specifying 3-9 subsequent repeats means 4-10 successive occurences in total....
How about using JFormattedTextField with MaskFormatter. JFormattedTextField formattedTextField = new JFormattedTextField("00:00:00;00"); try { MaskFormatter maskFormatter = new MaskFormatter("##:##:##;##"); maskFormatter.install(formattedTextField); } catch (ParseException e) { e.printStackTrace(); } More info at http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html Demo code: JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JFormattedTextField...
sql,regex,oracle,oracle11g,regexp-like
Try this one: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr(*)'); Fiddle This one also seems to work as far as I can tell: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr.'); Or another one that works: SELECT * FROM employee WHERE regexp_like(fname,'^pr'); ...
This matches all given examples as well: ^\$?\d+(?:[.,:]\d+)?%?$ See it in action: RegEx101 Please comment, if adjustment / further detail is required....
try this to get capture first digit: [^0-9]*(\d+) DEMO PHP Code: <?php $link = 'http://www.example/data/showall.php?quantity=&lang=eng&sura=2&ayat=21'; preg_match('/[^0-9]*(\d+)/',$link,$matches); echo $matches[1]; ?> Output: 2 ...
You need to change your [^/\s]+ to be lazy, rather than greedy, so it only matches up to the first .. Add a ? to the end. Note: [^\s] is every character that isn't whitespace, and / is not whitespace, so you can change it to just [^\s]. In addition,...
why have two '\' before 's' and 't'? In regex the \ is an escape which tells regex that a special character follows. Because you are using it in a string literal you need to escape the \ with \. and what's this "[\s\t\xa0\u3000]" mean? It means to match...
If you need the comments, you still can replace the 6th comma with a semicolon and use your previous solution: gsub("((?:[^,]*,){5}[^,]*),", "\\1;", vec1, perl=TRUE) Regex explanation: ((?:[^,]*,){5}[^,]*) - a capturing group that we will reference to as Group 1 with \\1 in the replacement pattern, matching (?:[^,]*,){5} - 5 sequences...
$pattern = '! ^ # start of string \d{5} # five digits [[:alpha:]]{2} # followed by two letters - # followed by a dash \d{2} # followed by two digits $ # end of string !x'; $matches = preg_match($pattern, $input); ...
Very well. Taking inspiration from this answer, the regular expression you are looking for is: values.split(/,(?=(?:[^']*'[^']*')*[^']*$)/) This will not work if you have escaped quotes, for example (e.g. "'O\'Reilly\'s car'"). However, this looks a bit like an XY problem. If you want to parse CSV, as it seems, and if...
\d+(?:[,.]\d+)? Try this.This should do it for you....
Zero-width negative lookahead/lookbehind (https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx#grouping_constructs) is what you should be using to make sure there are no quotes at the start or end. That way you don't need to know about the exact JSON format when you do the replacement: string pattern = @"(?<![""\w])(\d{17,})(?![""\w])"; string content = Regex.Replace(content, pattern, "\"$1\""); This...
You can match ASCII number codes by using \x to match escaped hexadecimal codes, e.g: \x02 should match STX...
python,regex,nsregularexpression
You're not capturing the whole filename in the group. You can also use noncapturing groups with (?:...). .*\.(rom|[0-9]{3})+ # from this (.*\.(?:rom|[0-9]{3})) # to this ...
python,regex,string,loops,twitter
Store slangNames and riskNames as sets, split the strings and check if any of the words appear in both sets slangNames = set(["Vikes", "Demmies", "D", "MS", "Contin"]) riskNames = set(["enough", "pop", "final", "stress", "trade"]) d = {1: "Vikes is not enough for me", 2:"Demmies is okay", 3:"pop a D"} for...
The search order is left to right on the searched string; then left to right on the pattern for the same initial position in the searched string. Thus, if you are looking for r"b|c" in "dcba", "c" is found first, since it closest to the start of "dcba" than "b"....
There's a bug in your code. As a string is immutable in JavaScript, replace doesn't change it but returns a new one. You do the replacement but you doesn't take the returned value Change val.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); to val = val.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); Demonstration...
Prologue: Don't downvote if you don't understand the answer. At least leave a comment stating what you object. Oracle database can do that. Example query: WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$') You want to select an regexp from a column, See SQL Fiddle example below for an example. SQL Fiddle Choose Oracle database....
regex,apache,.htaccess,url,rewriting
ok , I assume you want to change the URI from http://www.example.com/result.php?team=arsenal&player=ospina to http://www.example/subdirectory/arsenal/ospina.html so this is the .htaccess that will do that for you RewriteEngine on RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$ RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301] you can test it with htaccess tester here http://htaccess.madewithlove.be/ and some useful links for documentation and...
jquery,regex,string,substring,substr
You could convert this to a slightly more maintainable format, without getting into regular expressions. This is one way to use an array to accomplish your goal: // Super-quick one-liner: var str = '2042038423408'; var matchCount = $.grep(['12', '23', '34', '45', '56', '67', '78', '89', '90', '01'], function(num, i) {...
You can use the regex in a negative look-ahead and then add a \w shorthand class to match alphanumeric symbols, or [a-zA-Z] with \b word boundaries: (?![0-9-+*/()x]|abs|pow|ln|pi|e|a?(?:sin|cos|tan)h?)\b[a-zA-Z]+\b See regex demo Since we are only allowing letters with [a-zA-Z], we can reduce this further to (?!x|abs|pow|ln|pi|e|a?(?:sin|cos|tan)h?)\b[a-zA-Z]+\b See another demo...
Use \d+ to match one or more digits. \b(?:http:\/\/)?(?:www\.)?example\.com\/g\/(\d+)\/\w put http:// and www. inside a capturing or non-caturing group and then make it as optional by adding ? quantifier next to that group. For both http and https, it would be (?:https?:\/\/)? DEMO...
You could use a negative lookahead which will exclude those having _FX following the initial alpha string ^ABD_DEF_GHIJ(?!_FX)(?:_\d{8})?$ see example here...
For anything between # and >: '(?<=#)[^#>]*(?=>)' This will match everything (excluding # and >) inside #> and the result won't include the # and > at starting and ending....
You can use python's built-in csv module to do this. j = next(csv.reader([string])); Now j is each item delimited by a , and will include commas if the value is wrapped in ". See j[2]....
What you're looking for is called a character class. A character class is a group of characters that you're saying can be matched at that position in the string. To make a character class you enclose your list of matchable characters in square brackets, like this: [.,:;!?] This will match...
This might work ()(?:((?:a|b))\.(\w+)|(c)())() It matches: DEMO...
Put dot and / inside a character class so that it would match .png or /png strings. var imageReg = /[\/.](gif|jpg|jpeg|tiff|png)$/i; Your regex would return true if there is a dot exists before png but here there exists a forward slash , so it fails....
The reason is that after finding the first result, the regex engine continues its walk at the position after this first result. So the zero at the end of the first result can't be reuse for an other result. The way to get overlapping results is to put your pattern...
You can use this simplified regex: /^[\s0]*11\s*$/ ...
Some notes about your original regex: a lookahead only makes sense at the end of the string; you were probably looking for a non-capturing group, e.g. T(?:P-) instead of T(?=P-), but you don't even need those if they appear exactly once (i.e. if there's no need to put a *,...
python,html,regex,beautifulsoup,html-parsing
Yes, you can pass a regular expression pattern too: soup.find('div', {"class": re.compile("^divnew")}) Or, a function, checking that a class name starts with divnew: soup.find('div', {"class": lambda x: x and x.startswith("divnew"))}) Or, with a CSS selector: soup.select("div[class^=divnew]") ...
regex,list,join,ironpython,findall
You can simply do x="a85b080040010000" print re.sub(r"(.{2})",r"\1 ",x) or x="a85b080040010000" print " ".join([i for i in re.split(r"(.{2})",x) if i]) ...
You may try this, - ((?:(?!\((?:not|yes)\)).)*)(?=\s|$) DEMO or - (.*?)(?=\s+\((?:not|yes)\)|$) This would capture all the chars until a space(yes) or space(no) or end of the line is reached. DEMO...
This is about as simple as I can get it: \b\w+\.?\w* See demo...
You can use: Public\s+Const\s+g(?<Name>[a-zA-Z][a-zA-Z0-9]*)\s+=\s+(?<Value>False|True) demo ...
But how can I replace the only 45 with any other digit? You can use the replace function with matching groups : For example — Here I replace the 45 with 7 : "name[one][1][two][45][text]".replace(/(.*?)(two\]\[)([0-9]*)(.*)/,function (a,b,c,d,e){ // replace 7 with what you want return b+c+'7'+e; }) Result : "name[one][3][two][7][text]" Notice...
python,regex,string,list,python-2.7
With such a small range you could just iterate the move_order and check if each element exists in the allowed moves def start(): move_order=[c for c in raw_input("Enter your moves: ")] moves = ['A','D','S','C','H'] for c in move_order: if c not in moves: print "That's not a proper move!" return...
The .net regex implementation gives the possibility to store the substrings of a repeated capture group. So with this pattern that describes the whole string: \A(?:(\d+(?:-\d+)?)(?:,|\z))+\z (where \A and \z stand for the start and the end of the string) you obtain all the values in capture group 1 with...
The second repl parameter to re.sub can be an arbitrary function that takes a single match object and returns a string to replace it. In your case: >>> import re >>> repl = [2.888, 4.033] >>> re.sub( r'\d\.\d+', # note raw string to avoid issues with backslashes lambda match: str(repl.pop(0)),...
php,regex,apache,.htaccess,mod-rewrite
You can add a new rule for +/- conversion: Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^([^+]*)\+(.*)$ $1-$2 [R=302,NE,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] ...
Use the alternation with $: import re mystr = 'HelloWorldToYou' pat = re.compile(r'([A-Z][a-z]*)') # or your version with `.*?`: pat = re.compile(r'([A-Z].*?)(?=[A-Z]+|$)') print pat.findall(mystr) See IDEONE demo Output: ['Hello', 'World', 'To', 'You'] Regex explanation: ([A-Z][a-z]*) - A capturing group that matches [A-Z] a capital English letter followed by [a-z]* -...
Try library(stringr) str_extract(word, '.*(?=\\.csv)') #[1] "dirtyboards" Another option which works for the example provided (and not very specific) str_extract(word, '^[^.]+') #[1] "dirtyboards" Update Including 'foo.csv.csv', word1 <- c("dirtyboards.csv" , "boardcsv.csv", "foo.csv.csv") str_extract(word1, '.*(?=\\.csv$)') #[1] "dirtyboards" "boardcsv" "foo.csv" ...
The problem here is that re.search returns a match object not the match string and you need to use group attribute to access your desire result. If you wants all the captured groups you can use groups attribute and for a special group you can pass the number of expected...
.* is greedy: it matches all possible characters. This way, even sed 's/<?php.*//' file will also delete all the content in your file. To prevent this greediness of .*, say "everything but a ?" -> [^?]*: sed 's/<?php[^?]*?><?php[^?]*?>//' file Test $ cat a <?php echo 'first' ?><?php echo 'second' ?><?php...
Use {} instead of () because {} are not used in XPath expressions and therefore you will not have confusions.
The pattern attribute has to match the entire string. Assertions check for a match, but do not count towards the total match length. Changing the second assertion to \w+ will make the pattern match the entire string. You can also skip the implied ^, leaving you with just: <input pattern="(?!34)\w+"...
Using preg_match_all(), something like this probably works http://www.phpliveregex.com/p/bz0 # '/(?<!\S)(?i:[a-z\d]{4}|[a-z\d]{12})(?!\S)/' (?<! \S ) # whitespace boundary (?i: # case insensitive cluster group [a-z\d]{4} # 4 alnum | # or [a-z\d]{12} # 12 alnum ) (?! \S ) # whitespace boundary ...
Using sqlite3 from bash on OS X seems fairly straightforward (I'm no expert at this, by the way). You will need to find out which table you need. You can do this with an interactive session. I'll show you with the database you suggested: /Users/fredbloggs> sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db SQLite version...
First you have unnecessary escaping inside your character class. Your regex is same as: String pattern = "[(?=)]"; Now, you are getting an empty result because ( is the very first character in the string and split at 0th position will indeed cause an empty string. To avoid that result...
$1 is the value captured by the first capture (()), but you have no captures in your pattern. Fix: /(?<=File `..\/)(.*)(?=')/ Simplified: m{File `../(.*)'} More robust: m{File `../([^']*)'} ...
You can make use of a Unicode category \p{Zs}: Zs Space separator $string = preg_replace('~\p{Zs}~u', ' ', $string); The \p{Zs} Unicode category class will match these space-like symbols: Character Name U+0020 SPACE U+00A0 NO-BREAK SPACE U+1680 OGHAM SPACE MARK U+2000 EN QUAD U+2001 EM QUAD U+2002 EN SPACE U+2003 EM SPACE...
Your first regular expression has a black slash followed by the letter b because of that @. The second one has the character that represents backspace. Just put an @ in front string bound = @"\b"; ...
Use a negative lookahead assertion. string.replaceAll("test(?![^<>]*>)", "tested") Explanation: test - Matches the string test only if it's not followed by Any char but not of < or >, zero or more times. Further followed by > char. So this matches all the test except the one present inside <> ...
Find what: ^(.{30}) Replace with: \1\n ...
You turn off case sensitivity using an i inline flag in regex: (?i)https?:\\/.* See Foundation Framework Reference for more information on available regex features. (?ismwx-ismwx) Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (?i) changes to a case insensitive...
regex,scala,parsing,lexical-analysis
In a double quoted string backslash is an escape character. If you mean to use the literal backslash in a double quotes string you must escape it, thus "\d" should be "\\d". Furthermore you do not need to escape the regex dot within a character class, since dot has no...
You can use this regex to test. It will ensure that after the @ there is .xx. but may also match the string @.xx.* .*@[^.]*[.]xx[.] Or this one to ensure that there is at least one character before and after the @. [email protected][^.]+[.]xx[.] ...