jEdit Community - Resources for users of the jEdit Text Editor
RegExp - Replace special characters in a string
Submitted by jrchilds on Thursday, 15 January, 2009 - 20:00
I am writing a macro that will take highlighted text, convert any non alpha numeric characters to underscores, and then open a .chm file to the topic named by the resulting string. I can make everything except the regular expression part of that work. I only yesterday started playing with regular expressions, and I'm not sure how to do this, and google was not much help. Here is what I need.... I have, SomeVariable= "?This!String@1#2&3." I need to make SomeVariable= "_this_string_1_2_3_" Here is the set I want to replace [!@#$%^&*()<>{}[]?~`|\/] Is this an easy thing to achieve? Thanks for the help.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
I hope this isn't homework.
by elberry on Fri, 16/01/2009 - 01:34
I hope this isn't homework.

First off, take a look at the Pattern class in Java:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

There's almost an exact example on that page.

But one way would be to use this regex: "[^a-zA-Z0-9]"

As in, "not alpha-numerics". Smiling

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
Beanshell Function Solution
by jrchilds on Fri, 23/01/2009 - 21:58
I used a beanshell function to accomplish this if anyone is interested.

myString= myString.replaceAll("[^a-zA-Z0-9]", "_");

Cheers
 
Thanks, not homework...
by jrchilds on Fri, 16/01/2009 - 16:21
Thanks for the help. No, it isn't homework, I am a software developer and just never had a chance to learn RegEpxs.
 
Cool. Well then, welcome to t
by elberry on Fri, 16/01/2009 - 17:30
Cool. Well then, welcome to the wonderfully powerful world of Regular Expressions. Smiling

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300