regex

Sublime Text regex to find and replace whitespace between two xml or html tags?

≯℡__Kan透↙ 提交于 2021-02-04 15:15:46
问题 I'm using Sublime Text and I need to come up with a regex that will find the whitespaces between a certain opening and closing tag and replace them with commas. Example: Replace white space in <tags>This is an example</tags> so it becomes <tags>This,is,an,example</tags> Thanks! 回答1: This will find instances of <tags>...</tags> with whitespace between the tags (<tags>\S+)\W(.+</tags>) This will replace the first whitespace with a comma \1,\2 Open Find and Replace [OS X Cmd+Opt+F :: Windows

How to get the digits before some particular word using regex in c#?

拈花ヽ惹草 提交于 2021-02-04 14:56:55
问题 We will use below regex to get the digits before the words. Example : 838123 someWord 8 someWord 12 someWord (\d+)\s*someWord But sometimes anything will come between Number and word.Please see the below example line. Ex: 43434 of someword 12 anything someword 2323 new someword How to get the exact digit before that word using regex? Please give me your suggestions. 回答1: Do this: (\d+)[^\d]+some[wW]ord You need to accept anything other than digits themselves. Also I considered both w and W

Fastest, easiest, and best way to parse an HTML table?

╄→гoц情女王★ 提交于 2021-02-04 14:53:09
问题 I'm trying to get this table http://www.datamystic.com/timezone/time_zones.html into array format so I can do whatever I want with it. Preferably in PHP, python or JavaScript. This is the kind of problem that comes up a lot, so rather than looking for help with this specific problem, I'm looking for ideas on how to solve all similar problems. BeautifulSoup is the first thing that comes to mind. Another possibility is copying/pasting it in TextMate and then running regular expressions. What do

Another way instead of escaping regex patterns?

我的梦境 提交于 2021-02-04 14:25:38
问题 Usually when my regex patterns look like this: http://www.microsoft.com/ Then i have to escape it like this: string.match(/http:\/\/www\.microsoft\.com\//) Is there another way instead of escaping it like that? I want to be able to just use it like this http://www.microsoft.com, cause I don't want to escape all the special characters in all my patterns. 回答1: Regexp.new(Regexp.quote('http://www.microsoft.com/')) Regexp.quote simply escapes any characters that have special regexp meaning; it

Another way instead of escaping regex patterns?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-04 14:25:07
问题 Usually when my regex patterns look like this: http://www.microsoft.com/ Then i have to escape it like this: string.match(/http:\/\/www\.microsoft\.com\//) Is there another way instead of escaping it like that? I want to be able to just use it like this http://www.microsoft.com, cause I don't want to escape all the special characters in all my patterns. 回答1: Regexp.new(Regexp.quote('http://www.microsoft.com/')) Regexp.quote simply escapes any characters that have special regexp meaning; it

Regex to get currency and amount from string

守給你的承諾、 提交于 2021-02-04 14:01:48
问题 I have an Regex with me preg_match('/(?<=\$)\d+(\.\d+)?\b/', $str, $regs which return me the amount in a currency, but what i am trying is to get the symbol associated with the amount too. 1) E.g. the string is $300.00 asking price should return $300.00 but now it returns 300 2) E.g. the string is EUR 300.00 should return EUR300.00 but now it returns 300 Simply i want the currency with amount. Thanks 回答1: First, you match the currency which can be either $ or EUR , followed by optional white

Efficient way to extract text from between tags

元气小坏坏 提交于 2021-02-04 13:44:11
问题 Suppose I have something like this: var = '<li> <a href="/...html">Energy</a> <ul> <li> <a href="/...html">Coal</a> </li> <li> <a href="/...html">Oil </a> </li> <li> <a href="/...html">Carbon</a> </li> <li> <a href="/...html">Oxygen</a> </li' What is the best (most efficient) way to extract the text in between the tags? Should I use regex for this? My current technique relies on splitting the string on li tags and using a for loop, just wondering if there was a faster way to do this. 回答1: You

Efficient way to extract text from between tags

半城伤御伤魂 提交于 2021-02-04 13:44:06
问题 Suppose I have something like this: var = '<li> <a href="/...html">Energy</a> <ul> <li> <a href="/...html">Coal</a> </li> <li> <a href="/...html">Oil </a> </li> <li> <a href="/...html">Carbon</a> </li> <li> <a href="/...html">Oxygen</a> </li' What is the best (most efficient) way to extract the text in between the tags? Should I use regex for this? My current technique relies on splitting the string on li tags and using a for loop, just wondering if there was a faster way to do this. 回答1: You

How can i write the regex “All characters are the same”?

▼魔方 西西 提交于 2021-02-04 13:32:09
问题 I would like it to match: aaaaaa bb c but not: aaabaaa cd ... 回答1: Assuming the regex engine supports back-references, ^(.)\1*$ In Java it would be theString.matches("(.)\\1*") 回答2: Using back references: (.)(\1)* Read: match any character followed by that same character 0 or more times. Depending on the regexp engine and your needs, you might want to anchor the regex to only match the whole string, not substrings. 回答3: If you want to capture what you match, it is ^((.)\2*)$ 回答4: Just for

Chapter 7, Automate the boring stuff with Python, practice project: regex version of strip()

橙三吉。 提交于 2021-02-04 12:49:06
问题 I am reading the book "Automate the boring stuff with Python'. In Chapter 7, in the project practice: the regex version of strip(), here is my code (I use Python 3.x): def stripRegex(x,string): import re if x == '': spaceLeft = re.compile(r'^\s+') stringLeft = spaceLeft.sub('',string) spaceRight = re.compile(r'\s+$') stringRight = spaceRight.sub('',string) stringBoth = spaceRight.sub('',stringLeft) print(stringLeft) print(stringRight) else: charLeft = re.compile(r'^(%s)+'%x) stringLeft =