WebStorm - Unwrap text in quotes - webstorm

Is there a way to unwrap text in quotes?
I'm looking for something like this:
'my_var' -> some shortcut -> my_var

There is no such feature; please vote for WEB-15268 to be notified on any progress with it

Related

How to linebreak in REGEX with brackets

I got a list of data like exactly like that
51.9499, 7.555780000000027; 51.49705, 9.389030000000048; 51.249182, 6.991165099999989; 47.3163508, 11.09513949999996; 51.33424979999999, 12.574196000000029; 50.0297493, 19.196331099999952; 47.8270212, 16.25014150000004;
and I want to beautify it a bit by having linebreaks behind the "; " so it would rather look like
51.9499, 7.555780000000027;
51.49705, 9.389030000000048;
51.249182, 6.991165099999989;
...
I am using Adobe Brackets and I am trying to put a hard linebreak into the replace dialogue but that doesn't work - what would instead work?
In the replace bar, click on the .* icon to change the replace method to regular expression.
Then you can use ;\s* replace with ;\n to beautify your code accordingly.
You can see an example of this regex being run here.
Outputs the following:
51.9499, 7.555780000000027;
51.49705, 9.389030000000048;
51.249182, 6.991165099999989;
47.3163508, 11.09513949999996;
51.33424979999999, 12.574196000000029;
50.0297493, 19.196331099999952;
47.8270212, 16.25014150000004;

Regular Expression filter for Meta Fields

I want to parse text content to extract some parameters with Regular Expression.
My text looks like below:
//_META_FIELD{Parameter: S}
And, I want to filter content start with "//_META_FIELD{" and end with "}"
So, I can get the filtered content will : Parameter: S
Can any one help?
This Regex will find what you are looking for:
#^//_META_FIELD{(.+?)}$#m
^ is to make sure is at the beginning of the line and $ is to make sure nothing else is after that closing } You can remove that if you don't need it.
Also you can see an example of that RegExp here
The regex should look something like this:
^//_META_FIELD\{(.*?)\}$

How to remove all html tags except bold, italic, underline and new line?

I am not that good with regular expression so I am seeking help for this one.
I would like to know what is a regular expression for removing all html tags except for the following.
Bold
Italic
Underline
New Line
Thanks guys. hope you could help me on this one.
Jokes apart from this, don't try to parse HTML with Regex, use a HTML parser. It will make your life easy.
Google something or search here on SO about "HTML parser" + your language of choice.
replace regex with empty string <[]>.*?</[]>
and collect into [] all include tags, for example <[mas]>.*?</[mas]> capture <m>anything</m> <a>anything</a> <s>anything</s>
I am not sure why other answers think you need to parse the HTML. You just need to replace some patterns and not others. So you use a callback function for the regex replacement...
var keep = {
b: true,
i: true,
u: true,
br: true
};
html.replace(/<\/?([a-z]+) ?[^>]*>/g, function(wholeMatch, tagName)
{
if (keep[tagName]) {
return wholeMatch;
}
return '';
});
You can use regex first to replace the Bold , Italic , Underline Tags
to Temp string
Then Replace all html tags in to plain text
Replace temp string back in to Bold, Italic, Underline tag
Below is the link with detailed one with code.
http://techierocks.com/2018/07/remove-html-tags-css-styling-except-bold-italic-underline-new-line.html

Convert tags with regular expression

I wanna convert youtube tags...
my existing tags looks like this:
[video=youtube;puineN1UMto]http://www.youtube.com/watch?v=puineN1UMto&feature=related[/video]
And I want them to convert to:
[media=youtube]puineN1UMto[media]
How can I do that? Please guide.
Thanks
Something like this should work:
Search: %\[video=youtube;([a-zA-Z0-9]+)\].*\[\/video\]%
Replace: [media=youtube]\1[/media]

Regex to find string inside string inside string

Lets say I need to get a string inside some h1, h2, or h3 tags
/<[hH][1-3][^>]*>(.*?)<\/[hH][1-3]>/
This works great if the user decides to take a sane approach to headers:
<h1>My Header</h1>
but knowing my users, they want bold, italic, underlined h1's. And they have that coding quagmire tinyMCE to help them do it. TinyMCE would output:
<h1><b><span style='text-decoration: underline'><i>My Hideous Header</i></span></b></h1>
So my question is:
How do i get a string inside h1 h2, or h3, and then inside any amount of surrounding other tags as well?
Thanks,
Joe
/<(h[1-3])[^>]*>(?:.*?>)?([^<]+)(?:<.*?)?<\/\1>/i
It will not be too hard to make cases that break it hideously, since (as I'm sure people will tell you) parsing HTML is a job for an HTML parser, not a regex, but it works for your given case and various similar ones.
If you're in php you can use your regex:
/<[hH][1-3][^>]*>(.*?)<\/[hH][1-3]>/
then pass the captured result through strip_tags() function to get rid of all the insanity inside.
If you are not on php you can pass the result through regexp replace that removes tags. Something like replace
/<\/?[^>]+?>/
with empty string.
If you only want to capture the ultimately nested text you could just drop all tags inside the header tag with:
/<([hH][1-3]).*>(.*?)<.*\/$1>/
Untested, but I think it should work.