I’m trying to find a word on a sentence. The problem is that there 3 sentences, each one has it own word and can’t know when each one will be avaiable.
So sorry for delay, sure i’m gonna follow the course.
What i’m looking for is there’s sentences, which each one of them has a word that i would use later. The thing is that they aren’t always shown on same time. Sometime i could have “word1” sometimes “word2” etc…
So what i’m looking to do, is a regex code that can find the words i need what ever sentence is shown. If it’s the first one, it should give me word1 and so on.
A regex like /(?<=\/)\w+$/ will look at the end of the string, match the alphanumeric characters (\w equal to [a-zA-Z0-9_]) after the slash and extract those
let re = /(?<=\/)\w+$/;
let str = "/ser/ss/dat1/loc/word1";
let word = str.match(re)[0]; // match() returns an array, so I am accessing the first item in the array
console.log(word); // will print "word1"
then instead of \w you need to create the class of characters yourself
For example, \w is equal to [a-zA-Z0-9_], so the full stop is missing, if you substitute the class with the square parenthesis you can add and remove characters as you wish - this is a pretty easy thing to do, so I will let you do it it is good practice with regex