Regex match and return Word \w+ space \s

Hi 


I have something like this


TXTitem =
"
#Cadre: D4 Fire
#Slot: Dice
#type: Power
";


I need to get text after #Cadre:


How to get te full text with space.


I try this


var matches = /#Cadre: (\w+)\s/.exec(TXTitem);


or this


var matches = /#Cadre: (\w+)\s+/.exec(TXTitem);


but this return me only D4, i need get D4 Fire .


Regex  is very hard to understand!


Tanks


Here the full portion of code

Code:
//get the .note item selected
var TXTitem = $dataItems[DiceSlotBig[WhatSlotcliked][3]].note;
// Find in the .note item what have after #Cadre:
var matches = /#Cadre: (\w+)\s+/.exec(TXTitem);
console.log (matches[1]); // it supose to are D4 Fire but i have D4
//Show text to screen
$gameScreen.setDTextPicture('\\OW[4] ' + matches[1]  + ' ', 24); //affiche item id .name
$gameScreen.setFont('GameFont');
$gameScreen.showPicture(57, '', 1, TempX, TempY, 0, 0, 255, 0);
this.bindPictureToMap((57), 1, 'above_characters');
Regex makes my head hurt on good days, and today is not one of those. However, there is hope.


Go here: http://regexr.com/


Under Expression, put your regex. Under Text, put whatever text you like and if any of that text matches your regex requirements, it will be highlighted.
What you've got there is telling it to find text followed by a space.  You don't have anything to look for the text after the space.  And if you did, it'd return several strings rather than just one.


Try /#Cadre: ([\w\s]+)/
What you've got there is telling it to find text followed by a space.  You don't have anything to look for the text after the space.  And if you did, it'd return several strings rather than just one.


Try /#Cadre: ([\w\s]+)/



You rock @Shaz , Tank you a lot.


So now this work and return me word + space


var matches = /#Cadre: ([\w\s]+)/.exec(TXTitem);



Regex makes my head hurt on good days, and today is not one of those. However, there is hope.


Go here: http://regexr.com/


Under Expression, put your regex. Under Text, put whatever text you like and if any of that text matches your regex requirements, it will be highlighted.



Hey! tank you @Taarachnia , very nice link.


I was almost found solution, but @Shaz give me the soluce before 🙂


I keep this link to my Fav 


Tank you guys
I only found the solution because of that link 🙂
your more fast than me haha .!
What you've got there is telling it to find text followed by a space.  You don't have anything to look for the text after the space.  And if you did, it'd return several strings rather than just one.


Try /#Cadre: ([\w\s]+)/


Regex makes my head hurt on good days, and today is not one of those. However, there is hope.


Go here: http://regexr.com/


Under Expression, put your regex. Under Text, put whatever text you like and if any of that text matches your regex requirements, it will be highlighted.







For technical and dynamic reason, I'd rather pass the text to search with a variable.
I is not managed to do, how to do this as example.


I think we should call the object like this?


var new RegExp = /([\w\s]+)/;



But I'm completely lost.
If anyone can make out that the example of function down, working with the var txt passed
Tanks a lot.

Code:
function GetTXTnoteAfter(txt) {
var TXTitem = 'this is the sentence and need get thiss: blabla';
var matches = /txt ([\w\s]+)/.exec(TXTitem); /// txt are a variable with text to search = 'thiss:'
return matches;
}

GetTXTnoteAfter('thiss:'); // the text to search passed to function
var test = GetTXTnoteAfter();// get the return result of the function in var test


alert(test[1]); // show result var test, result need are  ( blabla )
console.log (test[1]); // result need are  ( blabla )
http://pastebin.com/07Dmbe6h


This is the More Escape Codes plugin that's shipped with MV.  In it, I let the user specify what the escape code will be to show a nickname, a face or a bust graphic.  Then I use regular expressions to build the pattern to search for - look at the definitions of reHandle and reHandlePattern on lines 96 and 97, reFace and reBust on lines 89 and 90 and their patterns on lines 189 and 190 (looking back, I don't know why I set up the patterns for the nickname in one spot and the face/bust in another).  Then lines 191 and 193 do the search for the face/bust patterns in the text, and line 121 handles the nickname replacement.
http://pastebin.com/07Dmbe6h


This is the More Escape Codes plugin that's shipped with MV.  In it, I let the user specify what the escape code will be to show a nickname, a face or a bust graphic.  Then I use regular expressions to build the pattern to search for - look at the definitions of reHandle and reHandlePattern on lines 96 and 97, reFace and reBust on lines 89 and 90 and their patterns on lines 189 and 190 (looking back, I don't know why I set up the patterns for the nickname in one spot and the face/bust in another).  Then lines 191 and 193 do the search for the face/bust patterns in the text, and line 121 handles the nickname replacement.

tanks  @Shaz 


there is a very good example of use, I will study Some lines, to make mine.
Thank you very much.
Hope I manage to understand.



my brain is boiling


the idea of my game,items .note is actually some little notes that will be used to identify them and gave them more detail.


Capture.JPG
It gets even easier in that case.


You can change your notes to something like this:

Code:
<Slot:Dice>
<Type:Power>
<Cadre:D4 Fire>
<DiceRun:4>

then in your code you can do this:


var item = $dataItems[128]; // if you already have a variable that contains the item object you don't need to do this
console.log(item.Slot); // this will print Dice to the console
console.log(item.Type); // this will print Power to the console
console.log(item.Cadre); // this will print D4 Fire to the console
console.log(item.DiceRun); // this will print 4 to the console

// then you can do stuff like this
if (item.Slot === 'Dice') {
// do stuff
} else {
// do other stuff
}


You don't need to bother with regular expressions at all!
It gets even easier in that case.


You can change your notes to something like this:

Code:
<Slot:Dice>
<Type:Power>
<Cadre:D4 Fire>
<DiceRun:4>

then in your code you can do this:



var item = $dataItems[128]; // if you already have a variable that contains the item object you don't need to do this
console.log(item.Slot); // this will print Dice to the console
console.log(item.Type); // this will print Power to the console
console.log(item.Cadre); // this will print D4 Fire to the console
console.log(item.DiceRun); // this will print 4 to the console

// then you can do stuff like this
if (item.Slot === 'Dice') {
// do stuff
} else {
// do other stuff
}


You don't need to bother with regular expressions at all!



OMFG !!!! lol by the hell !
Actually, that's not quite right.


It needs to be item.meta.Slot rather than just item.Slot.  Make sure there isn't a space between Slot: and Dice - so <Slot😀ice> rather than <Slot: Dice>.


Anything you put in the note box of any object on any database tab, as well as on the map, and that little note box beside an event name, in the format <key:value> is available to use under the object's meta property.  


You can also just put <key> without a value, and it will give you a true/false value based on whether that note is present.  So in my Actor Stepping Animation plugin (if you have an actor with wings and want it to use stepping animation on the map when not moving, for example), I can put <stepanim> in the note box, then in the plugin I can do if (actor.meta.stepanim) { ... } and it will execute that block of code if that actor has <stepanim> in the note box.
Actually, that's not quite right.


It needs to be item.meta.Slot rather than just item.Slot.


Anything you put in the note box of any object on any database tab, as well as on the map, and that little note box beside an event name, in the format <key:value> is available to use under the object's meta property.  


You can also just put <key> without a value, and it will give you a true/false value based on whether that note is present.  So in my Actor Stepping Animation plugin (if you have an actor with wings and want it to use stepping animation on the map when not moving, for example), I can put <stepanim> in the note box, then in the plugin I can do if (actor.meta.stepanim) { ... } and it will execute that block of code if that actor has <stepanim> in the note box.

it a very nice feature included that I did not know.
This will remove a workload.
I'll do a test and mamusé can with these great information.
Thank you.
 

Original thread: https://forums.rpgmakerweb.com/threads/regex-match-and-return-word-w-space-s.70074/