• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Remove special characters/regular expression from string.

 
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following code should it show it as link, but I am not sure about your target.
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. I will work out with your code and let you know the result. Thanks again.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always welcome.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The expected exact output will be like this.
AusteniticStainlessSteels --Class(link)
Alloys --subclass(link)---(some properties)
StainlessSteels --subclass(link)---(some properties)
Steels --subclass(link)---(some properties)


The above output's code from the fileis

 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the code and each and every word is displaying as link. I just want to retrieve the class links and subclass links from the file. Is it possible?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I want to list the links one by one. Now its printing next next. I tried addind `\n` at the end. But it was not working.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\n won't work in html add a <br> tag



Now with respect to your previous question, is it supposed to load any java class when clicked?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "<br>" tag I tried and its leaving some 10 empty lines and printing the remaining with line break.  

And the answer for the next question is as the following code path is mentioning some where its searching locally in my path itself.

 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a major issue.  What about your previous question?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope it will load as its searching locally from my folder structure. And the actual link it will load from So i guess it will load if i am giving exact link.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean when clicked it will search for the occurrence of this string in file and open the link?  
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. When clicking the link AusteniticStainlessSteels It will search for path and go to corresponding subclass.

 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by go to corresponding subclass?  
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Means the subclass is also a link which displays the properties of element when clicked.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is going to work this way.  The data is basically a xml format.  What appears to me is you have to parse the xml and build a tree structure kind view. When class is expanded, it displays all sub classes, and when sub class is expanded it displays all it's properties.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok then let me try some other way. How about white spaces? how to remove that.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trim()?
 
Marshal
Posts: 66189
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String#strip() is probably better than trim) but is only a Java11+ method.I doubt whether either is going to help you here.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trim() is not working. The first 11 lines are empty lines from 12th line its printing the text/link. In the following line one is commented and the other one uncommented. When printing I guess the regular expression get replaced from commented line too. Is it possible to not to remove the tags from commented line, and print the text/link once?

<!-- http://www.semanticweb.org/ontologies/2016/8/untitled-ontology-34#AFNOR_NF -->
<Class rdf:about="http://www.semanticweb.org/ontologies/2016/8/untitled-ontology-34#AFNOR_NF">
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried removing the commented lines too. But still its printing twice. I don't know why these are getting printed twice.

 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the same code printing twice, and are you sure you don't have duplicate lines in the file?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


One is commented line the other two is uncommented. But I tried removing both the lines. Still its printing twice.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print the class elements alone and not the type.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By removing do you mean you deleted the lines from file?
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is class element and what is type?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I tried deleting those lines. But no changes in output.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting, how come something is getting printed that doesn't even exist?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The first line is class and the second line is type under some other name.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too am surprised about that.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




In the first tag it comes under Nameindividual tag and in 2nd part of code it(AFNOR_NF) comes under class. I want to print them separately.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//see if it only prints class.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I said before, this is unlikely to work this way.  You need some kind of xml parsing.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. I will try running the code and let you know the result.
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried uploading the owl file for your reference. As i couldn't able to upload .owl,.txt,.xml extension file i am pasting the code here.

 
Sheriff
Posts: 6363
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To match "http" up to be not including the # sign, you can use this regex:

   (?=http)[^#]+

https://regex101.com/r/5F2uNr/1
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of string builder i can use the regular expression you have mentioned?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also as i am removing the regular expressions and just keeping the class names in my output, when clicking the link it is searching in my folder path. Is it possible to hide the entire url instead of removing?
 
Gayathri Gayu
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While keeping the cursor on the link it should either display the address or it should go to this path. Instead it is showing the address as my path
 
Knute Snortum
Sheriff
Posts: 6363
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:Instead of string builder i can use the regular expression you have mentioned?


You would still need some code, especially to weed out comments.  I'm not sure what you're using the StringBuilder for, but If you are only extracting the URL minus the label (text after the #) then I wouldn't think you wouldn't need them.

Other things to think about: more than one URL in a line; an open and close comment on a line with a legit URL after it; and probably more.
 
Knute Snortum
Sheriff
Posts: 6363
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:Also as i am removing the regular expressions and just keeping the class names in my output, when clicking the link it is searching in my folder path. Is it possible to hide the entire url instead of removing?


"Removing the regular expression" = removing what the regex matches?

"Keeping the class names in my output"  What class names?

"the link it is searching in my folder path."  I would think this would only happen if you have localhost as the root of your URL.  Can you explain more?

"Is it possible to hide the entire url instead of removing?"  What do you mean be "hide"?

It's really important that you use the precise terms for what you're talking about and explain exactly what you want done.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!