Find/Replace with Regex and Wildcard in the middle of the strings
-
I’d give it a try, but no exact text data was supplied, and I don’t type more than a few characters of data to try someone else’s problem.
People should follow the GUIDELINES.
-
Two reasons.
1.) YOU changed the text pattern by adding asterisks. If you want to make it work, change the search pattern accordingly, what to do here will be your first exercise in figuring out how to do regex.
2.) YOU have both lines selected. Put the cursor at the beginning of the first line before the
{
, and then hit the “Find Next” button and when it highlights the line hit the “Replace” button.Good luck.
-
@lycan-thrope said in Find/Replace with Regex and Wildcard in the middle of the strings:
The only thing I can think of
[deleted while I was replying]
When an OP complains that “the regex you supplied didn’t work” when it did work for you on your test data, your first thought should be, “is the data that I see in the OP actually the data being tested on?” And then you should look, and notice that part of the text is italic, which implies the presence of one or more
*
in the source data.And if you looked at @Dustin-McMillan’s screenshot that you’re replying to, you will see that
"
is in the data in Notepad++, whereas the forum is showing you quote characters. In fact, the screenshot also shows the asterisks that weren’t visible in the original post:in your replacement post:
YOU changed the text pattern by adding asterisks.
No. YOU assumed that the data you saw in the OP matched what the OP typed. You have been here long enough to KNOW that it’s not always the case. Any time the OP data is not in a black box, assume the data that you are seeing is wrong, or at least might be wrong.
YOU have both lines selected
Irrelevant, as two seconds of verification in your own Notepad++ could have shown you, even with your own test case.
@Dustin-McMillan , when you went to the “General Discussion” section of the forum, the very first thing you saw, immediately under “New Topic”, was “Please Read This Before Posting”
The reason why we put it so prominently is that reading that post will help you avoid confusion like this, wasting our time and yours with back-and-forth when the asker (you) and the answerer (us) have a different concept of the data. If you had read that post, it would have directed you to the GUIDELINES that @Alan-Kilborn just linked. Without making use of that formatting, everyone’s time gets wasted.
But to your real question: since there was actually an asterisk between the
/
and the date, you just have to edit the FIND regex to include\*
in the right spot (because\*
is the way to tell the regex engine to "look for a literal asterisk, instead of treating it as wildcard/quantity-modifier). (And that regex will work with or without having both lines selected.)----
Useful References
-
@lycan-thrope I apologize but the system here that we use to post questions removed the asterisks please see screen shot below not me. @Alan-Kilborn as it was my first time posting I was unaware and obviously missed the “read this before posting” so I apologize for “being a noob” and @PeterJones should I repost this question in the Help Wanted place or continue with this location? Also how would I make adjustments when this system doesn’t allow for astericks as shown in the shot below?
-
@peterjones said in Find/Replace with Regex and Wildcard in the middle of the strings:
No. YOU assumed that the data you saw in the OP matched what the OP typed. You have been here long enough to KNOW that it’s not always the case. Any time the OP data is not in a black box, assume the data that you are seeing is wrong, or at least might be wrong.
Obviously, not long enough. My bad. I guess I’ll just go back to lurking since I can’t figure out how to do this right yet. I’m just causing more problems than I’m solving. Thanks.
-
@dustin-mcmillan said in Find/Replace with Regex and Wildcard in the middle of the strings:
should I repost this question in the Help Wanted place or continue with this location?
Continue here. Help Wanted and General Discussion are indistinguishable in practical usage on this forum, and may both be used for questions.
Also how would I make adjustments when this system doesn’t allow for astericks as shown in the shot below?
Exactly in the way described in the GUIDELINES we’ve linked you to
twicethrice (including this link). -
@peterjones I understand what Guidlines says…however the system doesn’t allow me to type this it removes things in the “preview” screen so you aren’t seeing what I’m trying to actually solve for
-
@lycan-thrope said in Find/Replace with Regex and Wildcard in the middle of the strings:
I guess I’ll just go back to lurking since I can’t figure out how to do this right yet
This is rather harsh to yourself.
Cheers for wanting to help, and honestly, if someone jumps in and answers regex questions before me, I’m glad of it. My current philosophy is to just get these type of questions answered and out of the way quickly, as they really are data transformation questions (and thus Boost regex engine questions) rather than interesting Notepad++ questions.
-
@dustin-mcmillan said in Find/Replace with Regex and Wildcard in the middle of the strings:
I understand what Guidlines says…
If that were true we’d see a black box in one of your postings.
:-)
-
What part of the following example are you not understanding:
…
Do you notice the
```
characters before and after the example text? Because it was specifically called out above the template, it might be important example for formatting your posts.If the template isn’t clear enough for you – copy/paste the template, then overwrite the example phrasing with your actual data – then maybe you should read the more detail-oriented formatting forum posts which it links to, which explains the exact syntax involved, and how/why it works.
-
To put it another way, I have typed the same kinds of instructions dozens or hundreds of times in my history on this forum. I got tired of doing it long ago, and that’s why I put huge amounts of effort into writing the formatting-forum-posts and template-for-search/replace-questions and read-this-before-posting entries, so that I wouldn’t have to type it yet again.
But apparently, that’s not enough. Since I’ve typed these hundreds of times already, it won’t actually hurt to type it again.
``` {{=doDateDeltaFromCurrent("yyyy-MM-dd","-738180D");/*0001-01-01*/}} {{=doDateDeltaFromCurrent("yyyy-MM-dd","180D");/*0001-01-21*/}} ```
will render as
{{=doDateDeltaFromCurrent("yyyy-MM-dd","-738180D");/*0001-01-01*/}} {{=doDateDeltaFromCurrent("yyyy-MM-dd","180D");/*0001-01-21*/}}
… which I believe is an accurate representation of your data.
And, as a reminder, you have a working solution to this question, assuming that you can figure out where to type the
\*
in the regex you’ve already been given. We don’t need you to type your data again. Fixing the regex is literally as simple as typing those two characters right where I told you to type them, and @Lycan-Thrope’s regex will work for your actual example data. -
Unless your text changes anymore, this should be what works for what is assumed to be the text you provided:
Search:
{{.+;\/\*(\d+-\d+-\d+).*
Replace:$1
regular regex, do not check the checkbox. equals newline