I am looking for the regex to filter username just like the instagram usernames.
I don’t know much about regex but I can use it in my swift function.
As I know that regex algorithms changes depending on the programming language, so I need that instagram username regex for swift language.
Thanks
Instagram username rules
Two matches # mentions with no space between #thebox193#discodude
Matches with one . in them #disco.dude but not two .. #disco..dude
Beginning period not matched #.discodude
Ending period not matched #discodude.
Match underscores _ #_disco__dude_
Max characters of 30 #1234567890123456789012345678901234567890
Regex
(?:#)([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)
More information here
https://blog.jstassen.com/2016/03/code-regex-for-instagram-username-and-hashtags/
This should work /^(?!...)(?!..$)[^\W][\w.]{0,29}$/igm
Fiddle for this: https://regexr.com/3cg7r
Related
I have some rows in some columns contains something like
#Invalid Ref: 234566
#Invalid Ref: 123445
#Invalid Ref: 235678
I am trying to use find and replace by regular expression to find any row that contains any of the above and replace it with empty
what is the best regular expression I can use?
If the last numbers are always six digits, this should work. See google's explanation for Regex Find Replace for more examples.
^#Invalid Ref: [0-9]{6}$
I am using the following formula to extract the substring venue01 from column C, the problem is that when value string in column C is shorter it only extracts the value 1 I need it to extract anything straight after the - (dash) no matter the length of the value text in column c
={"VenueID";ARRAYFORMULA(IF(ISBLANK(A2:A),"",RIGHT(C2:C,SEARCH("-",C2:C)-21)))}
There is a much simpler solution using regular expressions.
=REGEXEXTRACT(A1,".*-(.*)")
In case you are no familiar with Regular Expressions what this means is, get me every string of characters ((.*)) after a dash (-).
Example
Reference
REGEXTRACT
Test regular expressions
Cheat sheet for regular expressions
To answer bomberjackets question in the comment of Raserhin:
To select the part of the string before the "-"
=REGEXEXTRACT(A1,"(.*)-.*")
EXAMPLE
example of code
Adding to your original formula. I think if you'd use RIGHT and inside it reverse the order of the string with ARRAY then that may work.
=Right(A1,FIND("-",JOIN("",ARRAYFORMULA(MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1)))+1,1))))-1)
It takes string from the right side up to X number of characters.
Number of character is fetched from reversing the text, then finding
the dash "-".
It adds one more +1 of the text as it will take out so it accounts
for the dash itself, if no +1 is added, it will show the dash on
the extracted string.
The REGEX on the other answer works great too, however, you can control a number of character to over or under trim. E.g. if there is a space after the dash and you would like to always account for one more char.
How can I extract a specific word or words from a URL to display in another column on Google Spreadsheets? The URL is https://seatgeek.com/bands/katy-perry?p=3 and I have to extract "katy perry" from this URL. I also have to create a second formula that will display the same URL with a date from another column on the spreadsheet.
Look up regular expressions for VBA. This way you can perform pattern matching with a lot of flexibility.
Here:
http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/
or better yet, here:
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
How's this - change A3 as needed to match the Cell with the URL:
=SUBSTITUTE(MID(A3,SEARCH(";",SUBSTITUTE(A3,"/",";",4))+1,FIND("?",SUBSTITUTE(A3,"/",";",4))-SEARCH(";",SUBSTITUTE(A3,"/",";",4))-1),"-"," ")
What this is doing is switching out the '/' right before 'katy-perry' with a unique (to that cell) mark, the semi-colon. Then, using MID(), extract the info between the substituted ';' and the '?'.
Edit: This should work with any name length (i.e. 'katy-perry','katyyyyyy-peeerrryyy'). Note that it assumes that you will ALWAYS have a URL with four '/' before the artist's name.
The single sample URL you provided leaves one wondering if the configuration is going to be standard across many other URLs you may have listed. If this is typical of the way other URLs are constructed, you can identify the question mark and the last forward slash to parse out the katy-perry. Here is is in steps then altogether.
The following instructions assume that https://seatgeek.com/bands/katy-perry?p=3 is in A1.
Append a question mark to the end just in case there isn't one in the URL and use the first question mark found to strip off anything right of that.
=LEFT(A1, FIND("?", A1&"?")-1)
Replace all forward slashes with 99 spaces.
=SUBSTITUTE(LEFT(A1, FIND("?", A1&"?")-1), "/", REPT(" ", 99))
Peel off the right-most 99 characters and trim off extra spaces.
=TRIM(RIGHT(SUBSTITUTE(LEFT(A1, FIND("?", A1&"?")-1), "/", REPT(" ", 99)), 99))
The result should katy-perry. This formula is Google-Spreadsheet friendly.
I did some searching and in openoffice and excel it looks like you can simply add an * at the beginning or end of a character to delete everything before and after it, but in Google spreadsheet this isn't working. Does it support this feature? So if I have:
keyword USD 0078945jg .12 N N 5748 8
And I want to remove USD and everything after it what do I use? I have tried:
USD* and (USD*) with regular expressions checked
But it doesn't work. Any ideas?
The * quantifier just needs to be applied to a dot (.) which will match any character.
To clarify: the * wildcard used in certain spreadsheet functions (eg COUNTIF) has a different usage to the * quantifier used in regular expressions.
In addition to options that would be available in Excel (LEFT + FIND) pointed out by pnuts, you can use a variety of regex tools available in Google Sheets for text searching / manipulation
For example, RegexReplace:
=REGEXREPLACE(A1,"(.*)USD.*","$1")
(.*) <- capture group () with zero or more * of any character .
USD.* <- exact match on USD followed by zero or more * of any character .
$1 <- replace with match in first capture group
Please try:
and also have a look at.
For spaces within keyword I suggest a helper column with a formula such as:
=left(A1,find("USD",A1)-1)
copied down to suit. The formula could be converted to values and the raw data (assumed to be in ColumnA) then deleted, if desired.
To add to the answers here, you can get into trouble when there are special characters in the text (I have been struggling with this for years).
You can put a frontslash \ in front of special characters such as ?, + or . to escape them. But I still got stuck when there were further special characters in the text. I finally figured it out after reading find and replace in google sheets with regex.
Example: I want to remove the number, period and space from the beginning of a question like this: 1. What is your name?
Go to Edit → Find and replace
In the Find field, enter the following: .+\. (note: this includes a space at the end).
Note: In the Find and replace dialogue box, be sure to check "Search using regular expressions" and "match case". Leave the Replace field blank.
The result will be this text only: What is your name?
I am working on Google spreadsheet. I am trying to make a validation rule on the text length.
For example the text length must be equal to 12 characters which includes number, on dash and one capital character.
Example:
123-56C89112
I tried to search in google groups but no result! can you help in this please
You can use Data > Validation > Custom Formula is
=REGEXMATCH(B3, "^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*")
I'm not an expert on Regex so this may be a bit over the top, but it appears to work:
^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*
Debuggex Demo
This allows any string with exactly 12 characters, 1 upper case letter and 1 dash.
EDIT: The (Lookahead) Regex doesn't seem to work in Spreadsheets (see comment)
EDIT2: Using a custom function like the following seems to work, but only if you use warnings (instead of rejections) for some reason (bug?)
function test(myString) {
return myString.match("^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*")!=null;
}