regex

javascript regex optional minus

女生的网名这么多〃 提交于 2021-02-05 06:50:12
问题 I have the following function in javascript: function unString(String){ var justNumbers = /(?=.*\d)\d*(?:\.\d*)?/; var result = String.match(justNumbers); result *= 1; result = Math.round(result*100) / 100; return result; } The meaning of it is to extract the number out of every possible css value, so that it can be added or substracted or multiplied with other values: e. g. var newPadding = unString( $('#myID').css("padding-bottom") )*10 + "px"; Having modified my code I would now need the

Java / Replace all Quotation mark

…衆ロ難τιáo~ 提交于 2021-02-05 06:49:08
问题 I to replace all Quotation mark in sentence to some word. Input: hello (and "How" are you"?") Output: hello (and WORD are youWORD) I try this is Java: mySentence.replaceAll("[\"].*[\"]", "WORD"); But nothing happens. How I can resolve it? 回答1: You can use: String replaced = mySentence.replaceAll("\".*?\"", "WORD"); Or better: String replaced = mySentence.replaceAll("\"[^\"]*\"", "WORD"); //=> hello (and WORD are youWORD) 回答2: you could easilly do this by converting a string in a character

Java / Replace all Quotation mark

被刻印的时光 ゝ 提交于 2021-02-05 06:48:27
问题 I to replace all Quotation mark in sentence to some word. Input: hello (and "How" are you"?") Output: hello (and WORD are youWORD) I try this is Java: mySentence.replaceAll("[\"].*[\"]", "WORD"); But nothing happens. How I can resolve it? 回答1: You can use: String replaced = mySentence.replaceAll("\".*?\"", "WORD"); Or better: String replaced = mySentence.replaceAll("\"[^\"]*\"", "WORD"); //=> hello (and WORD are youWORD) 回答2: you could easilly do this by converting a string in a character

Matching quote wrapped strings in javascript with regex

偶尔善良 提交于 2021-02-05 06:43:05
问题 I need a regex for javascript for matching "{any group of chars}" <-- where that last " is not preceeded by a \ examples: ... foo "bar" ... => "bar" ... foo"bar\"" ... => "bar\"" ... foo "bar" ... goo"o"ooogle "t\"e\"st"[] => ["bar", "o", "t\"e\"st"] The actual strings will be longer and may contain multiple matches that could also include white space or regex special chars. I have started by trying to break down the syntax but not being strong with regex myself I got stuck pretty fast but i

RegEx for an invoice format

限于喜欢 提交于 2021-02-05 06:42:07
问题 I'm quite new to regular expressions and I'm trying to create a regex for the validation of an invoice format. The pattern should be: JjYy (all 4 characters are legit), used 0, 2 or 4 times e.g. no Y's at all is valid, YY is valid, YYYY is valid, but YYY should fail. Followed by a series of 0's repeating 3 to 10 times. The whole should never exceed 10 characters. examples: JyjY000000 is valid (albeit quite strange) YY000 is valid 000000 is valid jjj000 is invalid jjjj0 is invalid I learned

RegExp gives unexpected result when tested against `undefined`

a 夏天 提交于 2021-02-05 06:42:05
问题 I'm building a password strength validator that check whether password contains lower-case and upper-case characters. I use regular expressions for that and get unexpected results when provided password string is undefined - see screenshot below. I would expect both checks to return false , yet the first one returns true . Why does the first check return true ? 回答1: Javascript will attempt to convert the argument of test to a string if it's not one. So since: String(undefined) === "undefined"

RegEx for an invoice format

拜拜、爱过 提交于 2021-02-05 06:40:27
问题 I'm quite new to regular expressions and I'm trying to create a regex for the validation of an invoice format. The pattern should be: JjYy (all 4 characters are legit), used 0, 2 or 4 times e.g. no Y's at all is valid, YY is valid, YYYY is valid, but YYY should fail. Followed by a series of 0's repeating 3 to 10 times. The whole should never exceed 10 characters. examples: JyjY000000 is valid (albeit quite strange) YY000 is valid 000000 is valid jjj000 is invalid jjjj0 is invalid I learned

Why can't I find this string in RegEx?

橙三吉。 提交于 2021-02-05 06:39:46
问题 lines = [] total_check = 0 with pdfplumber.open(file) as pdf: pages = pdf.pages for page in pdf.pages: text = page.extract_text() for line in text.split('\n'): print(line) output data: Totaalbedrag excl. btw € 25,00 When I try to retrieve VAT from data: KVK_re = re.compile(r'(excl. btw .+)') KVK_re.search(data).group(0) output: AttributeError: 'NoneType' object has no attribute 'group' KVK_re = re.compile(r'(excl. btw .+)') KVK_re.search(r'excl. btw € 25,00').group(0) output: 'excl. btw € 25

regexp_extract in hive giving error

流过昼夜 提交于 2021-02-05 06:39:25
问题 I have some data in table e.g.: id,params 123,utm_content=doit|utm_source=direct| 234,utm_content=polo|utm_source=AndroidNew| desired data using regexp_extract: id,channel,content 123,direct,doit 234,AndroidNew,polo Query used: Select id, REGEXP_extract(lower(params),'(.*utm_source=)([^\|]*)(\|*)',2) as channel, REGEXP_extract(lower(params),'(.*utm_content=)([^\|]*)(\|*)',2) as content from table; It is showing error '* dangling meta character' and returning error code 2 Can someone help here

Match any characters more than once, but stop at a given character

百般思念 提交于 2021-02-05 06:38:46
问题 I am writing a regex that will be used for recognizing commands in a string. I have three possible words the commands could start with and they always end with a semi-colon. I believe the regex pattern should look something like this: (command1|command2|command3).+; The problem, I have found, is that since . matches any character and + tells it to match one or more, it skips right over the first instance of a semi-colon and continues going. Is there a way to get it to stop at the first