Remove specific words containing dots from a string
$begingroup$
Hi I got words that contain one of the following tokens: CO. PRO. IST.
How to clean my words from these tokens? Do you have any regex pattern?
for example the words :
convolutional NN in data science--> extract nothing
co. Neural N --> extract co
co NN --> extract nothing
Thanks!
r rstudio regex dplyr
$endgroup$
add a comment |
$begingroup$
Hi I got words that contain one of the following tokens: CO. PRO. IST.
How to clean my words from these tokens? Do you have any regex pattern?
for example the words :
convolutional NN in data science--> extract nothing
co. Neural N --> extract co
co NN --> extract nothing
Thanks!
r rstudio regex dplyr
$endgroup$
add a comment |
$begingroup$
Hi I got words that contain one of the following tokens: CO. PRO. IST.
How to clean my words from these tokens? Do you have any regex pattern?
for example the words :
convolutional NN in data science--> extract nothing
co. Neural N --> extract co
co NN --> extract nothing
Thanks!
r rstudio regex dplyr
$endgroup$
Hi I got words that contain one of the following tokens: CO. PRO. IST.
How to clean my words from these tokens? Do you have any regex pattern?
for example the words :
convolutional NN in data science--> extract nothing
co. Neural N --> extract co
co NN --> extract nothing
Thanks!
r rstudio regex dplyr
r rstudio regex dplyr
asked 18 hours ago
3nomis3nomis
1827
1827
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
you can use lookahead with str_extract from the stringr package.
e.g.
stringr::str_extract(string = "co.asdkhsda", pattern = "co(?=\.)")
# extracts 'co' only when followed by a literal '.'
stringr::str_extract("convolutional NN in data science", pattern = "co(?=\.)")
# extracts nothing, returns NA
The regex pattern
co(?=\.)
looks for 'co', followed by '\.'
The '\'-part is used to escape the special meaning of the '.'
The dot usually matches any character, and therefore need to be escaped.
New contributor
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45804%2fremove-specific-words-containing-dots-from-a-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
you can use lookahead with str_extract from the stringr package.
e.g.
stringr::str_extract(string = "co.asdkhsda", pattern = "co(?=\.)")
# extracts 'co' only when followed by a literal '.'
stringr::str_extract("convolutional NN in data science", pattern = "co(?=\.)")
# extracts nothing, returns NA
The regex pattern
co(?=\.)
looks for 'co', followed by '\.'
The '\'-part is used to escape the special meaning of the '.'
The dot usually matches any character, and therefore need to be escaped.
New contributor
$endgroup$
add a comment |
$begingroup$
you can use lookahead with str_extract from the stringr package.
e.g.
stringr::str_extract(string = "co.asdkhsda", pattern = "co(?=\.)")
# extracts 'co' only when followed by a literal '.'
stringr::str_extract("convolutional NN in data science", pattern = "co(?=\.)")
# extracts nothing, returns NA
The regex pattern
co(?=\.)
looks for 'co', followed by '\.'
The '\'-part is used to escape the special meaning of the '.'
The dot usually matches any character, and therefore need to be escaped.
New contributor
$endgroup$
add a comment |
$begingroup$
you can use lookahead with str_extract from the stringr package.
e.g.
stringr::str_extract(string = "co.asdkhsda", pattern = "co(?=\.)")
# extracts 'co' only when followed by a literal '.'
stringr::str_extract("convolutional NN in data science", pattern = "co(?=\.)")
# extracts nothing, returns NA
The regex pattern
co(?=\.)
looks for 'co', followed by '\.'
The '\'-part is used to escape the special meaning of the '.'
The dot usually matches any character, and therefore need to be escaped.
New contributor
$endgroup$
you can use lookahead with str_extract from the stringr package.
e.g.
stringr::str_extract(string = "co.asdkhsda", pattern = "co(?=\.)")
# extracts 'co' only when followed by a literal '.'
stringr::str_extract("convolutional NN in data science", pattern = "co(?=\.)")
# extracts nothing, returns NA
The regex pattern
co(?=\.)
looks for 'co', followed by '\.'
The '\'-part is used to escape the special meaning of the '.'
The dot usually matches any character, and therefore need to be escaped.
New contributor
New contributor
answered 15 hours ago
JaggeJagge
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45804%2fremove-specific-words-containing-dots-from-a-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown