Need better regex to test for "a" but not "ax" - regex

I use the following regex in SSRS to test for a particular column name in a parameter:
=IIf(InStr(Join(Parameters!ColumnNames.Value, ","), "x"), False, True)
This will hide a column on a report if it is not one of the chosen columns. This works just fine if there is not another column called "xy". The string being tested may be "z,x,w", in which case the test works fine; but it may also be "z,xy,w", in which case it will find "x" and display both "x" and "xy".
I tried checking for "x," which only works if "x" is not the last character of the string. I need to know the syntax to check for both "x," OR "x as the last piece of the string". Unfortunately "x" can have any length. The basic problem is I do not know how to use an OR in the IIF statement.
I tried the most obvious ways and kept getting errors. Using "\b" also does not work because there are no spaces in the string (so word boundaries are not applicable).

What you can do is add the delimiter to your check, so that way you're checking the exact string only and not any that just include it:
=IIf
(InStr("," & Join(Parameters!ColumnNames.Value, ",") & ",", ",x,") > 0
, False
, True)
So this will catch x but not xy.
One thing to note:
I have added a check to see of InStr > 0, as this returns an integer and not a boolean.

You want to match a specific column name in an array of column names but do this on a single line to include in the IIF statement.
Based on the last technique suggested in How can I quickly determine if a string exists within an array? your code would need to be.
=IIf((UBound(Filter(Parameters!ColumnNames.Value, "x", True, compare)) > -1), False, True)
It doesn't look like there is an actual Regex anywhere?

Related

Regex to detect string is x.x.x where x is a digit from 1-3 digits

I have values 1000+ rows with variable values entered as below
5.99
5.188.0
v5.33
v.440.0
I am looking in Gsheet another column to perform following operations:
Remove the 'v' character from the values
if there is 2nd '.' missing as so string can become 5.88 --> 5.88.0
Can help please in the regex and replace logic as tried this but new to regex making. Thanks for the help given
=regexmatch(<cellvalue>,"^[0-9]{1}\.[0-9]{1,3}\.[0-9]{1,3}$")
I have done till finding the value as 5.88.0 returns TRUE and 5.99 returns false, need to now append ".0" so 5.99 --> 5.99.0 and remove 'v' if found.
You can use a combination of functions, it may not be pretty, but it does the work
Replace any instance of v with an empty string using substitute, by making the content of the cell upper case, if we don't put UPPER(CELL) we could exclude any upper case V or lower case v(it will depend which function you use)
SUBSTITUTE(text_to_search, search_for, replace_with, [occurrence_number])
=SUBSTITUTE(UPPER(A1),"V","")
Look for cell missing the last block .xxx, you need to update a bit your regex to specified that the last group it's not present
^([0-9]{1}\.[0-9]{1,3} ( \.[0-9]{1,3}){0} )$
Using REGEXMATCH and IF we can then CONCATENATE the last group as .0
REGEXMATCH(text, regular_expression)
CONCATENATE(string1, [string2, ...])
=IF(REGEXMATCH(substitute(upper(A2),"V",""),"^([0-9]{1}\.[0-9]{1,3}(\.[0-9]{1,3}){0})$"),concatenate(A2,".0"), A2)
The last A2 will be replace with something similar than what we have until now, but before that we need to make small change in the regex, we want to look for the groups you specified were the last group it's present, that's your orignal regex, if it meets the regex it will put it in the cell, otherwise it will put INVALID, you can change that to anything you want it to be
^([0-9]{1}.[0-9]{1,3}.[0-9]{1,3})$
This it's the piece we are putting instead of the last A2
IF(REGEXMATCH(substitute(upper(A2),"V",""),"^([0-9]{1}\.[0-9]{1,3}\.[0-9]{1,3})$"),substitute(upper(A2),"V",""),"INVALID")
With this the final code to put in your cell will be:
=IF(REGEXMATCH(substitute(upper(A2),"V",""),"^([0-9]{1}\.[0-9]{1,3}(\.[0-9]{1,3}){0})$"),concatenate(SUBSTITUTE(UPPER(A2),"V",""),".0"),IF(REGEXMATCH(substitute(upper(A2),"V",""),"^([0-9]{1}\.[0-9]{1,3}\.[0-9]{1,3})$"),substitute(upper(A2),"V",""),"INVALID"))

String excerpts

I would like to copy a certain string (out of a longer range of strings in one cell) and show it in a different cell with Google Sheets. This is what is in the initial cell A1:A :
"String 1","String 2","String 3"
In B1:B I'd like ONLY String 3, so without the "" and the other strings.
Is this possible with spreadsheets?
Or is there any other way of doing so?
Update
So the task is to get word inside double quotes. And the mathcing string is placed in the end of text.
You may use regular expressions to deal with that, the basic formula is:
=REGEXEXTRACT(A1,"([^""]+)""$")
This will give a word inside "" from text in cell A1 at the end of text.
For example:
some text...,"Thisthat","https://www.url.com/de/Thisthat"
gives https://www.url.com/de/Thisthat
You may also use arrayformula:
=ArrayFormula(REGEXEXTRACT(A1:A3,"([^""]+)""$"))
Please, read more about this functions here and here.
Old answer
if you want strings to be on their rows, use this formula in B1:
=ArrayFormula(if(A1:A = "String 3";A1:A;""))
If you have cells in A1:A, which contain 'string 3', and you want to match them too, use this:
=ArrayFormula(if(REGEXMATCH(A1:A , "String 3"),"String 3",""))

Create an If statement comparing a custom field MS Word

I'm trying to create an if statement (in MS Word) that looks at a custom field.
The custom field is DocProperty Client_ABV
I want it to print a line of text if client_abv matches a certain value else be completely blank (or delete the empty line if possible)
I believe it needs to look something like this:
{IF DocProperty.Client_ABV="Test" "Print this line if Test",""}
I've very little experience with this function in Word but I have some with conditional programming.
Can anyone shed any light. I've been googling it for the last 45 minutes and have had little success with the example pages I've found.
Use Ctrl+F9 to insert the field code { brackets }. They look like wavy brackets, but these are actually special "escape codes" that tell Word this is a field code.
You need a pair of brackets for both the IF and the DocProperty fields.
When performing a string comparison it's a good idea to put "quotes" around the field code as well as around the literal string.
There is no punctuation in the DocProperty field code (no period). And no comma between the true/false evaluation, only a space between the closing " and opening ".
If a paragraph mark should be part of the true/false evaluation (for example, you want to suppress the paragraph mark if the comparison is false) include it inside the "quotes" for the evaluation result. The field code will look a bit odd, but that does work.
For example:
{ IF "{ DocProperty Client_ABV }"="Test" "Print this line if Test¶
" ""}

OpenRefine custom text faceting

I have a column of names like:
Quaglia, Pietro Paolo
Bernard, of Clairvaux, Saint, or
.E., Calvin F.
Swingle, M Abate, Agostino, Assereto
Abati, Antonio
10-NA)\u, Ferraro, Giuseppe, ed, Biblioteca comunale ariostea. Mss. (Esteri
I want to make a Custom text facet with openrefine that mark as "true" the names with one comma and "false" all the others, so that I can work with those last (".E., Calvin F." is not a problem, I'll work with that later).
I'm trying using "Custom text facet" and this expression:
if(value.match(/([^,]+),([^,]+)/), "true", "false")
But the result is all false. What's the wrong part?
The expression you are using:
if(value.match(/([^,]+),([^,]+)/), "true", "false")
will always evaluate to false because the output of the 'match' function is either an array, or null. When evaluated by 'if' neither an array nor 'null' evaluate to true.
You can wrap the match function in a 'isNonBlank' or similar to get a boolean true/false, which would then cause the 'if' function to work as you want. However, once you have a boolean true/false result the 'if' becomes redundant as its only function is to turn the boolean true/false into string "true" or "false" - which won't make any difference to the values function of the custom text facet.
So:
isNonBlank(value.match(/([^,]+),([^,]+)/))
should give you the desired result using match
Instead of using 'match' you could use 'split' to split the string into an array using the comma as a split character. If you measure the length of the resulting array, it will give you the number of commas in the string (i.e. number of commas = length-1).
So your custom text facet expression becomes:
value.split(",").length()==2
This will give you true/false
If you want to break down the data based on the number of commas that appear, you could leave off the '==2' to get a facet which just gives you the length of the resulting array.
I would go with lookahead assertion to check if only 1 "," can find from the beginning until the end of line.
^(?=[^\,]+,[^\,]+$).*
https://regex101.com/r/iG4hX6/2

Oracle regex separate diskgroup name and the rest

I have a column whose value is
col1
+ASM_DISK_GROUP_TIER1/mydb/data/myfile.111.326
i would like to split the string into something like this
ASM_DISK_GROUP_TIER1 /mydb/data/myfile.111.326 myfile.111.326
(without the +sign)
however
select regexp_substr(col1,'[^/]*') from dual
gives me +ASM_DISK_GROUP_TIER1
and i am clueless how to get the second and the third part i.e
/mydb/data/myfile.111.326 myfile.111.326
Oracle regular expression support is quite limited -- unlike other languages which let you use parentheses to get back parts of the match, in Oracle you can only get the whole matched string (or its start or end position with REGEXP_INSTR).
There are various ways to work around this if you have to, using regexp magic and arithmetic, but in this case you should admit that you are actually just looking for the first and last occurrence of / and code accordingly:
SELECT SUBSTR(col1, 2, INSTR(col1, "/") - 2) "Disk Group",
SUBSTR(col1, INSTR(col1, "/")) "Path",
SUBSTR(col1, INSTR(col1, "/", -1)) "File Name"
FROM ...
(Not tested).