Need text removed after space
Yamilet Brown last edited by
I need to remove the text after all this file numbers including the space before the text. The ultimate goal is to convert the column into a row and have the digits separated by a comma WITHOUT any leading spaces.
Here is what I have:
18.1 SECURITY KEY
18.2 OPTION SCHEDULE
23.16 PRF ASSIGNMENT
24 WARD LOCATION
78 HOSPITAL LOCATION
and this is what I am seeking:
Thank you in advanced for the help!!
PeterJones last edited by
Welcome to the Community Forum, @Yamilet-Brown. You said:
The ultimate goal is to convert the column into a row and have the digits separated by a comma WITHOUT any leading spaces.
Thank you for the before and after data: that helps.
You can do it using regular expressions. I came up with one that seems to do the trick, for me, with your test data.
- Find =
(?-s)= disable . match space
\d+\.?\d*= match one or more digits, followed by optional literal decimal point, followed by 0 or more digits
\K= assuming this much has been matched, clear that (so the replace won’t replace the numeric prefix).
\s+.*\R*= grab a space after the number, plus any characters to the end of the line, plus any EOL character(s)
(\Z)?= check if it’s the end of the line, and store in group #1
- Replace =
- This is using the cool “conditional” replacement described here: if group #1 matched in the Find expression, then replace the whole expression with NOTHING (don’t want a comma at the end of the file), otherwise replace everything with a comma.
- Search Mode =
☑ Regular Expression
If that isn’t sufficient, please read below, and give enough details to show why it wasn’t sufficient for your needs.
FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:
This forum is formatted using Markdown, with a help link buried on the little grey
?in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes (
"") to curly “smart” quotes (
“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is
c:\folder\*.txt, it will show up as
c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.
If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.
Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.
- Find =
Yamilet Brown last edited by
OMG!! it worked… thank you so so much ☻