Remove first char from string - Regex [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I have started using Workflow on iOS to help speed up tasks at work. One of those is entering delivery records into the computer (via the iPad barcode scan function) instead of manually writting down the ref code and then typing it in.
Workflow has a "Replace Text" function that can be used with regexs to strip out characters etc.
I have managed to find a regex to get rid of the last digit in a scan (a checksum digit, always a capital letter).
The regex is simple.
.{0}-$.
This goes in the "Find Text" field. The "Replace With" is left empty. It works wonderfully.
How can adapt this to work with other scan types with other scan types where I want to specically get rid of the FIRST character only? I've searched the forums but can only find long and difficult to interpret regexes that I am sure won't do what I am trying to achive, something simple by comparison.
An example is of what I mean is to convert "Y300006944" to "300006944"

You can use the following regex:
^.(.*)$
with a backreference $1 that you can use as replacement.
Good luck.

Thanks to those who contributed somehting useful :)
I got the it resolved by using the "Split Text" function in Workflow for iOS.
I gave it the command to split based on a customer char, "Y" in this case. It's enough in this simple case.

Related

Replacing a certain number of characters after a match in regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I want to find any instance of
\/Network\/Cambric Corporate Center\/
and replace the next 8 characters with nothing.
So something like this
\/Network\/Cambric Corporate Center\/1164.DEV1164
Turns into this
\/Network\/Cambric Corporate Center\/1164
I'm working with a baked in replace regular expression visual programming piece, and this is my first post to here ever so please ask if more info is needed. I basically just need it to look like this
\/Network\/Cambric Corporate Center\/1164
if there is another solution without having to use replace
It is for a frequently updated mass source of data that I need to edit to make more compatible with arrays
Try (\/Network\/Cambric Corporate Center\/).{8} and replace with $1 to keep the first group but not anything else.
Here's the regex with the replacement: https://regex101.com/r/F4Y4VD/1

Regex, take last match before suffix [duplicate]

This question already has answers here:
Tempered Greedy Token - What is different about placing the dot before the negative lookahead?
(3 answers)
Closed 4 years ago.
I know this is going to sound like the kind of question that's been asked hundreds of times. But I've been searching for over an hour and none of the solution I found worked in my case.
I have many different numbers of the form
\d*'?\d+\.\d\d
An example of string I work with would be
The base item costs 1'245.48, the tax is of 18.45 and the bonus of 250.00, the total price is of 1'013.93. In case of trouble, contact our e-mail. Bank account 784.45
I want to get ONLY the last match corresponding to my regex before e-mail, i.e 1'013.93. I would like to use only regex, no extra python, javascript or anything
I have tried code inspired by this Regex Last occurrence?, this How to capture only last match in Regex, this Find Last Occurrence of Regex Word, and many other expressions of my own, but so far there always seems to be one piece missing
For example, after successfully selecting the very last number with (\d*'?\d+\.\d\d)(?!.*\d*'?\d+\.\d\d), I tried (\d*'?\d+\.\d\d)(?!.*\d*'?\d+\.\d\d)(?=e-mail), which does not match anything.
Any insights?
You could try this:
((\d+')?\d+(\.\d+)?)(?=[^\d]+e-mail)
The first group matches the number you want. From regex101.com:
Something like this with an extra number format check:
((\d{1,3}')*(\d{1,3})\.\d{2})(?=\D+e-mail)
Demo

Capture everything after one word [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 6 years ago.
I am trying to make a regular expression capture any words in the specific line after the word Attachment:
This question is for work, so it is not a homework or test question. I took the paragraph below as an example from www.regular-expressions.info. I did not major in computers but Psychology so this is completely foreign to me. I've read the manuals for the last two days, and because this is going over my head, I don't know how to begin.
I have a task which involves me linking the attachments to a specific file with the same name saved in a folder (at least 500 attachments) on Adobe PDF. What I did before was to manually select the words and link it to a specific file in a folder, but it is tedious to do when they can go up to 500 attachments.
I was aware of an application plug-in called EVERMAP that you can download for Adobe to automatically link specific words to a specific file in a folder. However, it requires me to use regular expressions which again, I don't know how to use.
I will bold the words I want to capture in the paragraph below.
The repetition operator manual expand the match as far as they, and only come back if they must to satisfy the remainder.
Attachment: The repetition operator manual
The asterisk or star tells the engine to attempt to match the preceding token zero or more times. The plus tells the engine to attempt to match the preceding token once or more.
Attachment: Asterisk and stars engine
Attachment: (.+) should work in your case unless there are other exceptions to this rule. The regex simply tells the parser to capture 1 or more character after the word Attachment:. See here for the sample
Like #Kevin said, the Regex is simple. Use Attachment: (.+).
Maybe you are confused on how to use Regex. I don't know about the Evermap plugin, but you can copy all the text from the PDF to Sublime Text (text editor to open .txt but with a lot of features) and do Regex part there. And then, since you are not a programmer, you should remove other irrelevant data. So the Regex will be:
`^\s*Attachment:\s*(.+)$|^(?!Attachment:).+$`
And replace it with:
`\1`
\1 is a variable containing group value caught in ()
In Sublime Text find Find and Replace, then apply the Regex there. Don't forget to turn on the Regex mode.

Partial string matching in Mongodb [duplicate]

This question already has answers here:
How to query MongoDB with "like"
(45 answers)
Closed 7 years ago.
Lets say I have a bunch of mongodb records like so, which are all strings:
{myRecord:'foobarbazfoobaz'}
{myRecord:'bazbarfoobarbaz'}
{myRecord:'foobarfoofoobaz'}
{myRecord:'bazbarbazbazbar'}
I need to be able to partial string match in two ways:
1) I want to match on 'foobar' so it returns:
'foobarbazfoobaz'
'foobarfoofoobaz'
Note that here, 'foobar' is a partial string that is matched against any of the records from the beginning of the string. It doesn't matter if 'foobar' turns up later in the string. As long the first six characters of 'foobar' match against the the first six characters of the record, I want to get it back.
2) I need to be able match on 'baz%%%baz' so it returns:
bazbarbazbazbar
Here 'baz%%%baz' matches the first three characters of any of the records, ignores the next three, then matches against the final three. Again, it doesn't matter if this pattern occurs later in the string, I am just interested in if I can match it from the beginning of the string.
I think there is some kind mongo regex to do this (hopefully) but I am terrible when it comes to regex. Any help would be greatly appreciated.
This is for a web application where users are searching for sequences of events on a timeline and they will always have to search from the beginning, but can leave blanks in the search if they wish to.
You can try $regex operator
1) I want to match on 'foobar'
db.collection.find({"myRecord":{"$regex":"^foobar*"}})
I need to be able match on 'baz%%%baz'
db.collection.find({"myRecord":{"$regex":"^baz.{3}baz"}})
Hope it will help
Hang on - just found a way to deal with the second case, which turns out to be unexpectedly straightforward:
{"myRecord":{"$regex":"^baz.{3}.baz"}}
I probably should spend some time learning how to use regex!

replace in java with a regex doesn't replace from left to right [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 5 months ago.
I'm trying to do a markdown parser. Basically, right now I just want to transform something like: "this is a *italic* text" into "this is a <em>italic</em> text".
I have basically this:
html_text = html_text.replaceAll("\*(.+)\*", "<em>$1</em>");
Here's the problem. If I use replaceAll, in a string such as "this *is* a *test* ok." it doesn't replace it 2 times, only once. Anyway, it can be fixed using replaceFirst() several times, so it's no biggie, still I don't get why it's replaceAll() and it doesn't replace all...
Anyway, using replaceFirst() I get one replacement, with the result as follows: "this <em>is* a *test</em> ok." I don't know much about regex, but I want it to replace from left to right not use some arbitrary rule. This is, the first block it should find is "*is*" not "*is* a *test*" giving as a result "this <em>is</em> a *test* ok.". Anyway, doing it another time the output is: "this <em>is<em> a </em>test</em> ok." which is wrong. A left to right would give the right one which is: "this <em>is</em> a <em>test</em> ok."
Since I don't know much about regex and I've been looking for a while I've decided to just ask you guys.
TL.DR.: I want replaceFirst() to replace using a left to right order, not some arbitrary one.
Edit: A solution is not allowing the * symbol inside the search. replaceAll() works fine. Still allowing the search from left to right would solve the problem much more easily, so is it possible?
Try this:
\*([^*]+)\* (take 1 or more of anything but an asterisk)
or this:
\*(.+?)\* (non-greedy version of + so it takes the smallest match up to the asterisk)
Your (.+) is greedy, so it goes to the last asterisk and captures more than you want. The non-greedy regex is the more elegant one in my mind, but either one works.