I can't get my regexextract to work properly on google sheets.
I have imported data from one tab to another, like this:
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/1o52z55YdNha4T_tCsKcHkrbA5sR4C1GyxYuBmMGGqu0/edit#gid=0"; "SheetName 1!A2:G103")
This works fine and what Im importing are percentages. Now, what I'm trying to do is to use regex to extract the numbers and omit the '%' symbol.
Normally I would type: =VALUE(REGEXEXTRACT(A11,"\D+"))but it doesn't work. However, if I use this exact Regex on any 'normal' cell (cell that is not an import from another tab), it works.
Is there a reasong regex doesn't work on an imported value?
Edit:
I have to send surveys to clients to know if they are satisfied with the provided service. Customers will choose between a few options. I do that using google forms by creating one form, and I link it to a google sheet where the answers from the form are pasted:
On the same sheet, I've added a tab where I import the data from the previous tab, by using importrange:
As you can see, it works. But I want to take out the letters and the '%' symbol. I just want the numbers so I can run an AVG function.
Is there a way to do that?
Thanks
You can try the following:
=REGEXEXTRACT(A11,"(\d+)")
Here is the sample input and output data using the previous function:
I think the problem is just related to the capital "D" since you need to use "d" instead.
You can check this other post as a reference:
What does \d+ mean in regular expression terms?
Related
Trying to fetch meaning of an entered text from urban dictionary. The problem is that urban dictionary shows several definitions posted by different users. I've used 'importxml' for fetching the first page that shows up when someone searches for a particular word.
Now I want this data to be split in different columns so that I can get each definition in seperate column.
If we look at the fetched data, at the end of every definition there is "by username month dd,yyyy" string.
How can I use this string to split that raw data into definitions in separate columns?
Tried RegEx but could not figure it out because this is the first time I'm using Regex.
replace string to unique symbol and then split by it
to capture string use the pattern:
"by username .+ \d+,\d{4}"
As you can read here, regex is not the correct tool for parsing HTML.
In your situation I will use Google Apps Script in combination with a DOMParser library, as cheerio.
Example:
const content = getContent_('https://www.urbandictionary.com/define.php?term=nah');
const $ = Cheerio.load(content);
Logger.log($('.contributor').text());
Link To Spreadsheet
Sheet!1Name - Names are in Single Column
Sheet!2Names - Names are in First Name, Last Name columns.
What I'm trying to do is basically remove any suffixes, special characters, and spaces, capitalize that information, and combine it with information from another field.
I was able to figure out how to piece together some regex that seems to effectively get rid of suffixes and removes special characters. It's below. That's where my skill set stops.
={"PlayerKey";ARRAYFORMULA(UPPER(IF(ISBLANK(C2:C8),,PROPER(TRIM(REGEXREPLACE(C2:C8," Jr\.$| J$| Sr\.$| S$|IV$|III$|II$|\.|-|'",""))))))}
I'm having trouble nesting formulas - i believe what i need to do is nest both concat and substitute but not sure if that's the method to get the "Desired Output example" that is in the sheet. I'm also having trouble understanding what order to do things, which is why i'm having trouble with 2Name i think.
How's this in A1 of the new tab called MK.Help?
=ARRAYFORMULA({"Player Key";UPPER(TRIM(REGEXREPLACE(IF(MID(C2:C8,2,1)=".",INDEX(SPLIT(C2:C8," "),,1),LEFT(C2:C8))&D2:D8," Jr\.$| J$| Sr\.$| S$|IV$|III$|II$|\.|-|'",""))&E2:E8)})
I am trying to extract the hashtag info from a twitter data cell in google sheets.
We can call this Cell A1:
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
In a perfect situation I would be able to produce this in another cell extracted from A1:
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
I am lost how to do it using REGEXTRACT. I assume this is the best method, but any that gets the job done is good.
Thank you for any help!
You want to achieve the following conversion using the built-in functions in Google Spreadsheet.
From
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
To
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
If my understanding is correct, how about this answer?
Sample formula:
=TRIM(REGEXREPLACE(REGEXREPLACE(A1,"\[|\]|,",""),"{""text"":""(.+?)""""indices"":.+?}"," #$1"))
In this case, it supposes that the input value is put in the cell "A1".
The flow is as follows.
Replace \[|\]|, with "" using REGEXREPLACE.
Replace {""text"":""(.+?)""""indices"":.+?} with " #$1" using REGEXREPLACE.
The top space is removed with TRIM.
Result:
References:
REGEXREPLACE
TRIM
Hi I am pretty new to regex I can do some basic functions but having trouble with this. I need to change the link in the rss feed.
I have a url like this:
http://mysite.test/Search/PropDetail.aspx?id=38464&id=38464&listingid=129-2-6430678&searchID=250554873&ResultsType=SearchResult
and want to change it to updated site:
http://mysite.test/PropertyDetail/?id=38464&id=38464&listingid=129-2-6430678&searchID=250554873&ResultsType=SearchResult
Where only thing changed is from /Search/PropDetail.aspx
to /PropertyDetail/
I don't have access to the orginal rss feed or I would change it there so I have to use pipes. Please help, Thanks!
Use the regex control.
In it, specify the DOM address of the node containing your link (prefixed by "item.") within the "In" field. For the "replace" field type
(.*)//Search//PropDetail/.aspx
and in the "with" field type use:
$1//PropertyDetail//.*
I've 'escaped' the '/' character in the with field. However, I'm not sure you need to do this except before the '.*' Some trial and error may be needed.
Hopefully this will achieve the result you want.
I recently discussed editors with a co-worker. He uses one of the less popular editors and I use another (I won't say which ones since it's not relevant and I want to avoid an editor flame war). I was saying that I didn't like his editor as much because it doesn't let you do find/replace with regular expressions.
He said he's never wanted to do that, which was surprising since it's something I find myself doing all the time. However, off the top of my head I wasn't able to come up with more than one or two examples. Can anyone here offer some examples of times when they've found regex find/replace useful in their editor? Here's what I've been able to come up with since then as examples of things that I've actually had to do:
Strip the beginning of a line off of every line in a file that looks like:
Line 25634 :
Line 632157 :
Taking a few dozen files with a standard header which is slightly different for each file and stripping the first 19 lines from all of them all at once.
Piping the result of a MySQL select statement into a text file, then removing all of the formatting junk and reformatting it as a Python dictionary for use in a simple script.
In a CSV file with no escaped commas, replace the first character of the 8th column of each row with a capital A.
Given a bunch of GDB stack traces with lines like
#3 0x080a6d61 in _mvl_set_req_done (req=0x82624a4, result=27158) at ../../mvl/src/mvl_serv.c:850
strip out everything from each line except the function names.
Does anyone else have any real-life examples? The next time this comes up, I'd like to be more prepared to list good examples of why this feature is useful.
Just last week, I used regex find/replace to convert a CSV file to an XML file.
Simple enough to do really, just chop up each field (luckily it didn't have any escaped commas) and push it back out with the appropriate tags in place of the commas.
Regex make it easy to replace whole words using word boundaries.
(\b\w+\b)
So you can replace unwanted words in your file without disturbing words like Scunthorpe
Yesterday I took a create table statement I made for an Oracle table and converted the fields to setString() method calls using JDBC and PreparedStatements. The table's field names were mapped to my class properties, so regex search and replace was the perfect fit.
Create Table text:
...
field_1 VARCHAR2(100) NULL,
field_2 VARCHAR2(10) NULL,
field_3 NUMBER(8) NULL,
field_4 VARCHAR2(100) NULL,
....
My Regex Search:
/([a-z_])+ .*?,?/
My Replacement:
pstmt.setString(1, \1);
The result:
...
pstmt.setString(1, field_1);
pstmt.setString(1, field_2);
pstmt.setString(1, field_3);
pstmt.setString(1, field_4);
....
I then went through and manually set the position int for each call and changed the method to setInt() (and others) where necessary, but that worked handy for me. I actually used it three or four times for similar field to method call conversions.
I like to use regexps to reformat lists of items like this:
int item1
double item2
to
public void item1(int item1){
}
public void item2(double item2){
}
This can be a big time saver.
I use it all the time when someone sends me a list of patient visit numbers in a column (say 100-200) and I need them in a '0000000444','000000004445' format. works wonders for me!
I also use it to pull out email addresses in an email. I send out group emails often and all the bounced returns come back in one email. So, I regex to pull them all out and then drop them into a string var to remove from the database.
I even wrote a little dialog prog to apply regex to my clipboard. It grabs the contents applies the regex and then loads it back into the clipboard.
One thing I use it for in web development all the time is stripping some text of its HTML tags. This might need to be done to sanitize user input for security, or for displaying a preview of a news article. For example, if you have an article with lots of HTML tags for formatting, you can't just do LEFT(article_text,100) + '...' (plus a "read more" link) and render that on a page at the risk of breaking the page by splitting apart an HTML tag.
Also, I've had to strip img tags in database records that link to images that no longer exist. And let's not forget web form validation. If you want to make a user has entered a correct email address (syntactically speaking) into a web form this is about the only way of checking it thoroughly.
I've just pasted a long character sequence into a string literal, and now I want to break it up into a concatenation of shorter string literals so it doesn't wrap. I also want it to be readable, so I want to break only after spaces. I select the whole string (minus the quotation marks) and do an in-selection-only replace-all with this regex:
/.{20,60} /
...and this replacement:
/$0"ΒΆ + "/
...where the pilcrow is an actual newline, and the number of spaces varies from one incident to the next. Result:
String s = "I recently discussed editors with a co-worker. He uses one "
+ "of the less popular editors and I use another (I won't say "
+ "which ones since it's not relevant and I want to avoid an "
+ "editor flame war). I was saying that I didn't like his "
+ "editor as much because it doesn't let you do find/replace "
+ "with regular expressions.";
The first thing I do with any editor is try to figure out it's Regex oddities. I use it all the time. Nothing really crazy, but it's handy when you've got to copy/paste stuff between different types of text - SQL <-> PHP is the one I do most often - and you don't want to fart around making the same change 500 times.
Regex is very handy any time I am trying to replace a value that spans multiple lines. Or when I want to replace a value with something that contains a line break.
I also like that you can match things in a regular expression and not replace the full match using the $# syntax to output the portion of the match you want to maintain.
I agree with you on points 3, 4, and 5 but not necessarily points 1 and 2.
In some cases 1 and 2 are easier to achieve using a anonymous keyboard macro.
By this I mean doing the following:
Position the cursor on the first line
Start a keyboard macro recording
Modify the first line
Position the cursor on the next line
Stop record.
Now all that is needed to modify the next line is to repeat the macro.
I could live with out support for regex but could not live without anonymous keyboard macros.