Intellij regular expression search in XML atributes - java

I'm using Intellij and I want to search for XML attributes.
For example this XML line:
<img src="madonna.jpg" alt='Foligno Madonna, by Raphael' />
I want to search my project for any other instances of this line:
<img src="BLABLALBA" alt='BLABLALBA' />
I tried using this regular expression : src="\W" but no results was found.
Any help appriciated.

Try Structural Search & Replace (Edit | Find | Search Structurally...). Use the following pattern:
<img src="$A$" alt="$B$" />
And set the file type to XML or HTML depending on what type of files you are searching.

Related

Remove binary data from html file using Java Regex

I have html file that have tags for binary data like:
<HTML>
<BODY STYLE="font: 10pt Times New Roman, Times, Serif">
<TEXT>
begin 644 image_002.jpg
M_]C_X 02D9)1# ! 0 0 ! #_VP!# #&!#<&!0#'!P<)"0#*#!0-# L+
M#!D2$P\4'1H?'AT:'!P#)"XG("(L(QP<*#<I+# Q-#0T'R<Y/3#R/"XS-#+_
MVP!# 0D)"0P+#!#-#1#R(1PA,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R
,Z4]1]: %HHHIB/_9
end
</TEXT>
<TEXT>losses occurring in the third quarter and from weather </TEXT>
</BODY>
</HTML>
so I am trying to remove all "TEXT" tags those have binary data using Java Regex. I tried Jsoup library But it only remove html tags. I saw the same question here. But it is not using Java Regex.
Is any standard way to remove this binary data from html file?
It is well know that you shouldn't use a regex to handle xhtml.
I would use jsoup to remove the whole tag and later add it empty.
But if you want to use a regex, then you can use a regex like this:
"your html here".replaceAll("(?s)<TEXT>.*?<\\/TEXT>", "<TEXT></TEXT>")
Working demo
val regex = """<TEXT>\s*begin \d+ (?>[^e]+|e(?!nd\s*<\/TEXT>))*end\s*<\/TEXT>"""
Full example available here

Extract some data using Regex

I'm struggling some time to extract JSON data from one html tag. To be more specific it's a script tag and using JSOUP library I can get data between script tags. But inside there is some JSON data which I can't extract. Here is the tag:
<script type="text/javascript">jwplayer.key="WbtWzGvcRNi6Tk+gtKldIbx+nn6lXZFvKiaO2g==";jwplayer("tvplayer").setup({playlist:[{image: "http://img.canlitvlive.io/yayin/trt1_480.jpg?1509735585",title:"TRT 1 Canlı Yayın - CanliTVLive.io",file : "http://yayin.canlitvlive.io/trt1/live.m3u8?tkn=8JD95lXv9dOUXwtgOTBYfw&tms=1509749985"}],...</script>
I need url from file tag which is inside jwplayer. I tried using regular expression for example I tried somethig like this:
"playlist[\":\\s\\{]+file[\":\\s\\{]+\"([^\"]+)\""
But I don't have much experience with regex and can't figure out right pattern. Can someone help with this? Thanks
I'm guessing you just need some whitespace
file\s*:\s*"(.*?)"
https://regex101.com/r/4HldaP/3

pretty print java with no xml conversion

I am aware that this question has been asked multiple times on this site, however none of the previous answers have worked for me.
I have a String as XML like <A><B/><C></C></A>
When I use the pretty print converters I get:
<A>
<B/>
<C/>
</A>
I want to stop this and get the XML as it was. Like:
<A>
<B/>
<C></C>
</A>
I want an indent=2. Kindly help.
As mentioned in the comment section, for empty XML element tag both
<B></B>
and
<B/>
are equivalent.
I think you should try negotiate with your tester to save you the trouble as this sort of "fix" is deem as unnecessary. I would say your XML code is working as expected.
Try pointing your tester to the W3C XML specification.
See:
https://www.w3.org/TR/REC-xml/#NT-EmptyElemTag
Quote from the link above:
Examples of empty elements:
<IMG align="left"
src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>

Parse Jsp file and find specific tags using Java

I need a way to find specific tags in my class.
Example code :
<ace:column id="test1"></ace:column>
<ace:column id="test2"></ace:column>
<ice:panelGrid id="test3" columns="4" />
Now I want to process the file with above contents ,parse it and get all the tag values with identifier "id".
I would expect to get
test1
test2
test3
Thanks.
Use parsers. There are a lot of and for the tutorial on how to parse see this URL.
If you need to process the tags themselves, you would need to rely on some parser such as JSoup.
That being said, if all you want are the values following the id string, you could rely on regular expressions, somthing such as: id="([^"]*?)".

Adding name and id properties to textarea (struts)

i mostly do CSS and php so i'm kind'a lost here, so no idea if this is possible the way i want it anyway, this is it:
I have this code
<html:textarea rows="10" cols="70" property="thankYouMessage" />
And i want this textarea to render an id of "textareaID" and a name like "textareaname"
how can i go about this?... if i use styleID, the page just won't load anymore... i need to apply some css to that markup so that's the thing.
Thanks in advance!
styleId attribute should work (perhaps you mispelled it ? case is sensitive)
<html:textarea styleId="textareaID" property="thankYouMessage" ... />
IIRC (long time since Struts 1...) the generated name atribute in the HTML tag will coincide with the property attribute (ref). So in your example the generated HTML (you should check this, looking at the HTML source) should result in something like this:
<textarea id="textareaID" name="thankYouMessage" ...>
Normally you should'nt rely on name for accessing the element (e.g., in Javascript), prefer the id

Categories

Resources