Grab Mobile Phone Number from wrap data
-
Hi Here…
I have data like as:healthcare Pratik Mandiri dr. socmed balkisbalxxxx@gmail.com socmed +6208129311111 healthcare Praktek Umum socmed yulianaindixxxx@gmail.com socmed +6208154077777How to grab mobile phone number:
Pratik Mandiri dr. | 6208129311111
Praktek Umum | 6208154077777Or other result, grab mobile phone number only:
6208129311111
6208154077777Moderator here, I’ve surrounded the example data in a code box. Please refer to the FAQ post here for the correct method of showing examples.
-
Based only on the information you provided in your initial post, if you wanted to extract
Pratik Mandiri dr. | 6208129311111 Praktek Umum | 6208154077777you would go to the Find/Replace form (Ctrl+H with normal keybindings), check Wrap Around, set Search Mode to
Regular expression, and:
Find what:(?-si)healthcare\R(.*)\Rsocmed\R.*\Rsocmed\R\+(\d+)
Replace with:${1} | ${2}To understand the regular expression I wrote here, you can read the Notepad++ documentation on regular expressions.
In brief (italicized words or phrases are important concepts from regular expressions):
(?-si)is a flag that makes it so that all ASCII letters are matched case-sensitively (the default is to ignore case) and the.metacharacter matches non-newline characters- The
\Rescape sequence matches any newline (this could be\r\nfor Windows,\rfor Mac, or\nfor Linux) .*matches an entire line (including an empty line)- The
\descape sequence matches any one of the characters0123456789 - The
*metacharacter indicates that the preceding pattern should be matched 0 or more times - The
+metacharacter indicates that the preceding pattern should be matched 1 or more times - the
()wrapping(.*)and(\d+)create two capture groups that are referenced in the Replace With as${1}and${2}respectively - The Replace With has its own special syntax and set of special sequences that is different from the syntax for the Find what. For instance, in the Replace With syntax,
*and+and.have no special meaning; they’re just treated as normal characters.
Hopefully that’s enough information for you to tweak this regular expression as needed, in case what I gave you is not general enough to meet your needs.
-
Hello, @tcast-mobile, @mark-olson and All,
@tcast-mobile, just a variant which does not care about the
socmedstring but simply searches for the nearest multi-digits phone number, preceded by a+sign, beginning a line :FIND
(?-is)healthcare\R(.+)\R(?:.+\R)+?\+(\d+\R)REPLACE
$1 | $2
Notes :
Most of the explanations, relative to the regex syntax, have already been given by Mark. Two other points :
-
The
(?:......)syntax is a non-capturing group, as we do not need this information in replacement -
The
\+represents a literal+
Best Regards,
guy038
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login