I am using importxml function to extract some info
=IMPORTXML("url","//span[#class='circle-with-text grade-D']")
I need to replace D with any other letter,trying to use "" or '' or '?' etc with no results.
"AN?" idea?
'=IMPORTXML("url","//span[#class='circle-with-text grade-D']")'.replace(/D/,"A"); It's the only capital D.
Use SUBSTITUTE.
As per the Help Docs:
SUBSTITUTE
Replaces existing text with new text in a string.
SUBSTITUTE(text_to_search, search_for, replace_with, [occurrence_number])
text_to_search - The text within which to search and replace.
search_for - The string to search for within text_to_search.
search_for will match parts of words as well as whole words; therefore a search for "vent" will also replace text within "eventual".
replace_with - The string that will replace search_for.
occurrence_number - [ OPTIONAL ] - The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced.
So:
=IMPORTXML("url",SUBSTITUTE("//span[#class='circle-with-text grade-D']", "D", "A"))
replaces all Ds in the formula with As.
Related
Consider the the following text
The capital asset as defined in section 2(14) is an exhaustive definition which encompasses all properties of any kind with certain exceptions but the key word is that the property should be "held" section 2.
Now I want to find section 2, for the same I have written the following Regex:
/\bsection+\.*\s+2\b/i
But it is also matching section 2 of section 2(14). I just want it to only match the exact text, not the part of text which is matching with the regex. I know I need to modify the regex, but what are the changes required?
Try with \bsection+\.*\s+2([ .,;?|!])/i . This will only match with section 2 if it is followed by a space or a punctuation mark different than (.
/\bsection+.*\s+2\b([[:punct:]]|\s/
basically you would want the word to end with whitespace or a punctuation.
I am trying to use word wrap such that it can wrap a single long string of text within an array on multiple lines.
I found the link below to be somewhat helpful:
http://apidock.com/rails/ActionView/Helpers/TextHelper/word_wrap
I copied the regex listed in the link above, which matches a single long string within an array:
def breaking_wrap_wrap(msg, col = 80)
msg.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,"\\1\\3\n")
end
However, I'm not sure how to fix the regex to match the string within the array:
undefined method `gsub' for ["adsgagsdgds"]:Array
I couldn't get it to work in Rubular or another gsub testing tool, so was wondering if anyone knew how to match the array above and break the line if a single string in the array is greater than 80 characters?
Thanks!
Is it possible to get a text with whitespaces?
Example rule:
rule: 'text' text+=ID+
I can obtain the text as a list and could add a whitespace programmatically for each list element, but i don't want that approach. I actually don't need a list. I want one single variable holding the text with whitespaces.
STRING works fine, but it has those ugly quotes, i don't want those quotes as well.
Maybe someone has an idea how to achieve that?
You can use a Datatype-Rule like this:
rule: 'text' text+= MyText ;
MyText:
ID+
;
Lookup some details in the Reference Documentation in the section Data Type Rules.
The Mongoid documentation only gives one example of doing a wildcard search:
Person.where(first_name: /^d/i)
This finds all people with the first name that starts with "d".
What do the /^ and /i represent?
How do I find all people with their first name having an "na" in the middle of the string? E.g., this query would find "jonathan" since "na" is a substring of the entire string.
Is there website or guide with this information?
You need this to find people with "na" in the name.
Person.where(first_name: /na/i)
As for your example:
Person.where(first_name: /^d/i)
^ means "beginning of the line". This regex will match all strings where first letter is "d". /i means "do case-insensitive matches". So it'll match both "d" and "D".
Note: only prefix regexes (with ^ in front) are able to use indexes.
Is there website or guide with this information?
Here's my favourite.
This is not a "wildcard" search, this is called a regular expression.
/^d/i
The two slashes are only the regex delimiters, you search for what is in between those two slashes.
The following i is a modifier or option. It changes the matching behaviour of your regex, the i stands for case insensitive, means it matches "d" and "D".
The first character ^ is an anchor, it anchors the search pattern to the start of the string, means match "d" only at the start of the string
A good tutorial about regular expressions is the tutorial on regular-expressions.info
If you want to search for a string anywhere in the string, just remove the anchor that binds the pattern to the start, /na/ will find "na" anywhere in the string.
I have string "(1,2,3,4,5,6),(1,2,3)" I would like to change it to "('1','2','3','4','5','6'),('1','2','3')" - replase all parts that mathces /([^,)("])/ with the '$1', '$2' etc
"(1,2,3,4,5,6),(1,2,3)".gsub(/([^,)("]\w*)/,"'\\1'")
gsub is a "global replace" method in String class. It finds all occurrences of given regular expression and replaces them with the string given as the second parameter (as opposed to sub which replaces first occurrence only). That string can contain references to groups marked with () in the regexp. First group is \1, second is \2, and so on.
Try
mystring.gsub(/([\w.]+)/, '\'\1\'')
This will replace numbers (ints/floats) and words with their "quote-surrounded" selves while leaving punctuation (except the dot) alone.
UPDATED: I think you want to search for this
(([^,)("])+)
And replace it with this
'$1'
the looks for anything 1 or more times and assigns it to the $1 variable slot due to using the parenthesis around the "\d". The replace part will use what it finds as the replacement value.