I have a large file in xCode that contains numerous occurrences of bezierPath (ie bezier456Path). What I'd like to do is come up with a regular expression for this string so I can replace it simply with the string "bezierPath". I've tried things like bezier\w*Path to no avail. Does anyone know what I could use to search for a string like this?
\w is for word characters. Based on your example, you need to search for digits (\d):
bezier\d+Path
Also, since your replacement string is bezierPath, there is no point in using * (i.e. zero or more), since that would include replacing bezierPath with itself. Therefore, you should use + (i.e. one or more), instead.
I don't have access to xcode, but can't you use Find with
(bezier.*?Path)
and then use Replace with the path that you want, so in this case just bezierPath
Related
I am reading a text from an application using BluePrism. The text has the following structure (the number varies from case to case): "Please take note of your order reference: 525". I need to be able to extract the number from the text. Looking at the calculation stage, there is a replace function: replace(text, pattern, new-text). I want to use this function to replace all alphabetic characters in my text with an empty string to return only whatever is numeric. How can I input that in the pattern?
So I want something like this:
Replace([Order confirmation text ], /^[A-z]+$/, " ")
Also, I tried to look for a proper documentation for the VBOs that are shipped with blueprism, but couldn't find any. Does anyone know where we can get documentations for blueprism functions?
The Replace() function in calculate stage is the simplest possible one. It's not a regex one!
So, if the stirng is always in that format, then you can use:
Replace([Text],"Please take note of your order reference:","")
If the text is not always that standard, then you should rather use a regular expressions. To do that, you need to use an object, that will invoke a regex code.
In the standard blueprism objects, you can find:
Object: Utility - Strings C#
Action: Extract Regex Values
I think there is no Regex Replace action, by default, so if you'd like to, then you have to implement it. Below you can find a code that I am using:
Dim R as New Regex(Regex_Pattern, RegexOptions.SingleLine)
Dim M as Match = R.Match(Text)
replacement_result = R.Replace(Text,Regex_Pattern,replacement_string)
Quick Answer if the pre text is constant use a Mid statement then this will take out the issue the other guy had with the right. i.e.
Mid("Please take note of your order reference: 525",42,6)
If you aim for a maximum number length it will stop at the end anyway.
A few things here:
-Your pattern isn't matching because it's looking for a constant string of letters from start to finish (^ anchors to the beginning of the string and $ anchors to the end).
-You're replacing the pattern with a space, not an empty string, so you'll end up with a bunch of spaces in your result even if you correct the pattern.
-You said you only want to replace alphabetic characters, but it looks like you also want to get rid of spaces and colons.
Try replacing [A-Za-z :]+ with "".
Your goal is to retrieve number from string then use Right():
Right("Please take note of your order reference: 525", 3)
This will return only numeric.
Regards
Vimal
I have a string of text and numbers which to all intents and purposes looks like a long string of random text.
I need to detect multiple + or multiple - which are either next to each other or spread out throughout the string.
So, for example I need to detect these:
abc+abc+abc-abc-
or
abc++abc--
abc could be numbers or characters. The text could contain zero or one + and zero or one - in any order, at the beginning or anywhere through.
Could someone please assist with a regex (vba compatible) which would assist in determining these?
Many thanks
You don't need to use a single regular expression. Using other methods can be a lot clearer and more straightforward: remove matches for [^+-] to filter out the characters you don't want, then use ([+-])\1 to do the final validation.
I'm trying to find all pages which contain words "text1" and "text2".
My regex:
text1(.|\n)*text2
it doesn't work..
If your IDE supports the s (single-line) flag (so the . character can match newlines), you can search for your items with:
(text1).*(text2)|\2.*\1
Example with s flag
If the IDE does not support the s flag, you will need to use [\s\S] in place of .:
(text1)[\s\S]*(text2)|\2[\s\S]*\1
Example with [\s\S]
Some languages use $1 and $2 in place of \1 and \2, so you may need to change that.
EDIT:
Alternately, if you want to simply match that a file contains both strings (but not actually select anything), you can utilize look-aheads:
(?s)^(?=.*?text1)(?=.*?text2)
This doesn't care about the order (or number) of the arguments, and for each additional text that you want to search for, you simply append another (?=.*?text_here). This approach is nice, since you can even include regex instead of just plain strings.
text0[\s\S]*text1
Try this.This should do it for you.
What this does is match all including multiline .similar to having .*? with s flag.
\s takes care of spaces,newlines,tabs
\S takes care any non space character.
If you want the regex to match over several lines I would try:
text1[\w\W]*text2
Using . is not a good choice, because it usually doesn't match over multiple lines. Also, for matching single characters I think using square brackets is more idiomatic than using ( ... | ... )
If you want the match to be order-independent then use this:
(?:text1[\w\W]*text2)|(?:text2[\w\W]*text1)
Adding a response for IntelliJ
Building on #OnlineCop's answer, to swap the order of two expressions in IntelliJ,you would style the search as in the accepted response, but since IntelliJ doesn't allow a one-line version, you have to put the replace statement in a separate field. Also, IntelliJ uses $ to identify expressions instead of \.
For example, I tend to put my nulls at the end of my comparisons, but some people prefer it otherwise. So, to keep things consistent at work, I used this regex pattern to swap the order of my comparisons:
Notice that IntelliJ shows in a tooltip what the result of the replacement will be.
For me works text1*{0,}(text2){0,}.
With {0,} you can decide to get your keyword zero or more times OR you set {1,x} to get your keyword 1 or x-times (how often you want).
I am stuck in between of a problem where only one pass of regular expression is allowed( some old hard code). I need the regex for roman numerals.
I have tried the standard one i.e. ^(?i)M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$, but the problem is it allows null('') values also.
Is there any way around to check is problem?
To require that at least one character must be present, you can use a lookahead (?=.) at the start of your regular expression:
^(?=.)(?i)M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$
Another solution is to separately test that your string is not the empty string.
I like this one:
\b(?=[MDCLXVI]+\b)M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b
I need a regular expression to list accepted Version Numbers. ie. Say I wanted to accept "V1.00" and "V1.02". I've tried this "(V1.00)|(V1.01)" which almost works but then if I input "V1.002" (Which is likely due to the weird version numbers I am working with) I still get a match. I need to match the exact strings.
Can anyone help?
The reason you're getting a match on "V1.002" is because it is seeing the substring "V1.00", which is part of your regex. You need to specify that there is nothing more to match. So, you could do this:
^(V1\.00|V1\.01)$
A more compact way of getting the same result would be:
^(V1\.0[01])$
Do this:
^(V1\.00|V1\.01)$
(. needs to be escaped, ^ means must be on the beginning of the text and $ must be on the end of the text)
I would use the '^' and '$' to mark the beginning and end of the string, like this:
^(V1\.00|V1\.01)$
That way the entire string must match the regex.