regex

Extract digits from string - Google spreadsheet

早过忘川 提交于 2021-01-20 15:50:33
问题 In Google spreadsheets, I need a formula to extract all digits (0 to 9) contained into an arbitrary string, that might contain any possible character and put them into a single cell. Examples (Input -> Output) d32Ελληνικάfe9j.r/3-fF66 -> 329366 h01j2j3jFxF$$4j5j6j7j8j9 -> 0123456789 回答1: You may replace all non-digit characters using the \D+ regex and an empty string replacement with =REGEXREPLACE(A11,"\D+", "") or with casting it to a number: =VALUE(REGEXREPLACE(A11,"\D+", "")) 回答2: These

Perform a non-regex search/replace in vim

女生的网名这么多〃 提交于 2021-01-20 15:19:40
问题 When doing search/replace in vim, I almost never need to use regex, so it's a pain to constantly be escaping everything, Is there a way to make it default to not using regex or is there an alternative command to accomplish this? As an example, if I want to replace < with < , I'd like to just be able to type s/</</g instead of s/\</\&lt\;/g 回答1: For the :s command there is a shortcut to disable or force magic. To turn off magic use :sno like: :sno/search_string/replace_string/g Found here:

How to add backslash before every special character in php

我怕爱的太早我们不能终老 提交于 2021-01-20 14:01:34
问题 I want to add backslash before every character in php below is my string AT POST :- SARIGAM, (BHANDARI STREET) PIN : 396155 STATE: GUJARAT VALSAD GUJARAT 396155 India Some special character are not i this string but answer should be valid for all the special character. I have tried below, but not able to success. if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $address)) { str_replace('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', "\\", $address); } 回答1: You can just use preg_replace to replace all non

How to add backslash before every special character in php

℡╲_俬逩灬. 提交于 2021-01-20 14:00:29
问题 I want to add backslash before every character in php below is my string AT POST :- SARIGAM, (BHANDARI STREET) PIN : 396155 STATE: GUJARAT VALSAD GUJARAT 396155 India Some special character are not i this string but answer should be valid for all the special character. I have tried below, but not able to success. if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $address)) { str_replace('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', "\\", $address); } 回答1: You can just use preg_replace to replace all non

Remove first n words and take count

南笙酒味 提交于 2021-01-20 13:53:43
问题 I have a dataframe with text column, I need to ignore or eliminate first 2 words and take count of string in that column. b <- data.frame(text = c("hello sunitha what can I do for you?", "hi john what can I do for you?") Expected output in dataframe 'b': how can we remove first 2 words, so that count of 'what can I do for you? = 2 回答1: You can use gsub to remove the first two words and then tapply and count, i.e. i1 <- gsub("^\\w*\\s*\\w*\\s*", "", b$text) tapply(i1, i1, length) #what can I

Remove first n words and take count

拥有回忆 提交于 2021-01-20 13:49:30
问题 I have a dataframe with text column, I need to ignore or eliminate first 2 words and take count of string in that column. b <- data.frame(text = c("hello sunitha what can I do for you?", "hi john what can I do for you?") Expected output in dataframe 'b': how can we remove first 2 words, so that count of 'what can I do for you? = 2 回答1: You can use gsub to remove the first two words and then tapply and count, i.e. i1 <- gsub("^\\w*\\s*\\w*\\s*", "", b$text) tapply(i1, i1, length) #what can I

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

a 夏天 提交于 2021-01-20 13:49:09
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

十年热恋 提交于 2021-01-20 13:47:18
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

南笙酒味 提交于 2021-01-20 13:47:05
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

Pass Java backreference to method parameter

泪湿孤枕 提交于 2021-01-20 09:42:16
问题 I need a Java port of this https://gist.github.com/jbroadway/2836900, which is basically a simple markdown regex parser in PHP. I was hoping I could use the backreferences, but I can't make it work. At the moment I'm not using a HashMap , I've got 2 JavaFX TextArea s where I'll get and set the text via a ChangeListener . { //... htmlTextArea.setText(markdownTextArea.getText() .replaceAll("(#+)(.*)", header("$0", "$1", "$2")); } private String header(String text, String char, String content) {