Discussion:
supernewbie question (regex)
(too old to reply)
Jeff D. Hamann
2005-10-06 13:58:07 UTC
Permalink
I've got to modify a javascript script (if that's what I'm supposed to call
them) to perform the following operation on a string:

· Eliminate all vowels except for a leading vowel (i.e., first
character is a vowel).



RESERVIOR ---> RSRVR



MEASUREMENT ---> MSRMNT



· Reduce double-consonants to a single instance of the consonant.



ADDRESS ---> ADRS


· If the algorithm results in the formation of a double consonant,
then reduce the double consonant to a single instance of the consonant.



STATION ---> STTN ---> STN

I've never written any javascript code before (I'm modifying a small script
so much of the basic work is done) and I need to perform a few search and
replaces on a string (remove the vowels, and double consonants), rinse and
repeat.

Any hints?

Jeff.



---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
541-754-1428
***@forestinformatics.com
www.forestinformatics.com
Evertjan.
2005-10-06 14:06:18 UTC
Permalink
Post by Jeff D. Hamann
I've got to modify a javascript script (if that's what I'm supposed to
· Eliminate all vowels except for a leading vowel (i.e., first
character is a vowel).
RESERVIOR ---> RSRVR
MEASUREMENT ---> MSRMNT
· Reduce double-consonants to a single instance of the
consonant.
ADDRESS ---> ADRS
· If the algorithm results in the formation of a double
consonant, then reduce the double consonant to a single instance of
the consonant.
STATION ---> STTN ---> STN
I've never written any javascript code before (I'm modifying a small
script so much of the basic work is done) and I need to perform a few
search and replaces on a string (remove the vowels, and double
consonants), rinse and repeat.
Any hints?
Jeff.
Seems to me it is school exam work, Jef,
or is it your son or daugter,
as I cannot find any other useful purpose.

Better show us what you have done sofar, this is not a payed helpdesk.

Hint: Search Google for javascript, regex and replace
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Jeff D. Hamann
2005-10-06 17:43:54 UTC
Permalink
Nope. It's for a database naming convention compliance task. From a real IT
department...

And no, I'm looking for payed helpdesk support (that's my job) but IT is
buit a small part of the mask tasks at hand...

As I mentioned I'm a real newbie with javascript (let's save the flaming for
later shall we...) and since I've got experience with PHP, here's what I
have done so far...

<?

// $name = "sp_summaries";
$name = "station";
print( $name. "\n" );
$new_name = ereg_replace( "[AaEeIiOoUu]", "", $name );

print( $new_name. "\n" );

// nope...what goes in here? might need the forward/backward thingy...
// $last_name = ereg_replace( "[A-ZA-z]", "" , $new_name );
// print( $last_name. "\n" );

?>

I found some good information at
http://www.regular-expressions.info/duplicatelines.html once I realized what
question I needed to ask (thanks again for the jab)..

But I'm not sure how to impliment it in Javascript (did I mention I'm a
freakin' newbie!)...

I then founnd the following code @
http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256F100058EE66


function removeDuplicates(field) {
var temp = field.value;
var array = temp.split(" ");
array.sort();
temp = array.join(" ");


do {
var newTemp = temp;
var temp = newTemp.replace(/\s(\w+\s)\1/, " $1");
} while (temp.length != newTemp.length);

temp = temp.replace(/^(\w+\s)\1/, "$1");
temp = temp.replace(/(\s\w+)\1$/, "$1");

var orig = field.value.split(" ");
var finalStr = "";
for (var i=0; i<orig.length; i++) {
if (temp.indexOf(orig[i] + " ") != -1) {
finalStr += orig[i] + " ";
temp = temp.split(orig[i] + " ").join(" ");
} else if (temp.indexOf(" " + orig[i]) != -1) {
finalStr += orig[i] + " ";
temp = temp.split(" " + orig[i]).join(" ");
}
}

if (finalStr.substring(finalStr.length-1, finalStr.length) == " ") {
finalStr = finalStr.substring(0, finalStr.length-1);
}
field.value = finalStr;
}

But again, I need to impliment this for single letters so where do I remove
the spaces between words requirements...

Does this look like newbie territory to you?

I'll credit you with a "thanks" which you can cash in on once you're
helpful. Will you be helpful or do you have excess time to spend bashing
newbies?

Jeff.
Post by Evertjan.
Post by Jeff D. Hamann
I've got to modify a javascript script (if that's what I'm supposed to
· Eliminate all vowels except for a leading vowel (i.e., first
character is a vowel).
RESERVIOR ---> RSRVR
MEASUREMENT ---> MSRMNT
· Reduce double-consonants to a single instance of the consonant.
ADDRESS ---> ADRS
· If the algorithm results in the formation of a double
consonant, then reduce the double consonant to a single instance of
the consonant.
STATION ---> STTN ---> STN
I've never written any javascript code before (I'm modifying a small
script so much of the basic work is done) and I need to perform a few
search and replaces on a string (remove the vowels, and double
consonants), rinse and repeat.
Any hints?
Jeff.
Seems to me it is school exam work, Jef,
or is it your son or daugter,
as I cannot find any other useful purpose.
Better show us what you have done sofar, this is not a payed helpdesk.
Hint: Search Google for javascript, regex and replace
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Evertjan.
2005-10-06 18:05:24 UTC
Permalink
Post by Jeff D. Hamann
Post by Evertjan.
Seems to me it is school exam work, Jef,
or is it your son or daugter,
as I cannot find any other useful purpose.
Better show us what you have done sofar, this is not a payed
helpdesk.
Hint: Search Google for javascript, regex and replace
[please no topposting on usenet, this is not email]
Post by Jeff D. Hamann
Nope. It's for a database naming convention compliance task. From a
real IT department...
And no, I'm looking for payed helpdesk support (that's my job) but IT
is buit a small part of the mask tasks at hand...
As I mentioned I'm a real newbie with javascript (let's save the
flaming for later shall we...) and since I've got experience with PHP,
here's what I have done so far...
$new_name = ereg_replace( "[AaEeIiOoUu]", "", $name );
var line = 'database naming convention'
result = line.replace(/[aeiou]/ig,'')
document.write(result)

// dtbs nmng cnvntn
Post by Jeff D. Hamann
function removeDuplicates(field) {
var line = 'ADDRESS'
result = line.replace(/(.)\1/g,'$1')
document.write(result)

// ADRES
Post by Jeff D. Hamann
Post by Evertjan.
Post by Jeff D. Hamann
· If the algorithm results in the formation of a double
consonant, then reduce the double consonant to a single instance of
the consonant.
STATION ---> STTN ---> STN
var line = 'STATION'
result = line.replace(/[aeiou]/ig,'').replace(/(.)\1/g,'$1')
document.write(result)

// STN
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Evertjan.
2005-10-06 18:13:20 UTC
Permalink
Post by Evertjan.
var line = 'ADDRESS'
result = line.replace(/(.)\1/g,'$1')
document.write(result)
// ADRES
btw:

var line = 'ADdreesS'
result = line.replace(/(.)\1/g,'$1')
document.write(result)

// ADdresS

var line = 'ADdreesS'
result = line.replace(/(.)\1/ig,'$1')
document.write(result)

// ADres
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Jeff D. Hamann
2005-10-06 20:09:19 UTC
Permalink
WOW... Super-Genius! I have much to learn oh great one....

here's the chunk of code I've got now...

..blah, blah, blah...
// ENITITES
Log.Writeln("List of table names created from entity names:");
for (e=0; e<Model.CountEntities; e++)
{
Entity = Model.Entities(e);
EntityName = Entity.Name;
EntityTabName = EntityName;

//newTabName = replace(EntityTabName,letter_to_replace,replace_letter)
//Entity.TableName = newTabName;
//Log.Writeln("Table name '"+newTabName+"' based on entity
'"+EntityName+"' created.'");

// maybe this is going to work... maybe not... ugh...
//nTabName =
EntityTabName.replace('/[aeiou]/ig','').replace('/(.)\1/g','$1');
//nTabName = EntityTabName.replace('/[aeiou]/ig','');
//nTabName = EntityTabName.replace("[AaEeIiOoUu]",'');

// whew! this works thanks to ***@interxnl.net
nTabName =
EntityTabName.replace(/[aeiou_]/ig,'').replace(/(.)\1/g,'$1').toUpperCase();

Log.Writeln("Table name '" + nTabName + "' based on entity
'"+EntityName+"' created.'");

}
Log.Writeln();

..blah, blah, blah...

which results in...


..blah, blah, blah...
Table name 'PCTCVCT' based on entity 'pct_cov_cat' created.'
Table name 'PLTVST' based on entity 'plot_visit' created.'
Table name 'PRCDWNWD' based on entity 'proc_down_wood' created.'
Table name 'PRCTRS' based on entity 'proc_trees' created.'
Table name 'PRJCTS' based on entity 'projects' created.'
Table name 'SMPLRS' based on entity 'samplers' created.'
Table name 'SNGDCYCLSS' based on entity 'snag_decay_classes' created.'
Table name 'SPTLRFSYS' based on entity 'spatial_ref_sys' created.'
Table name 'SPCS' based on entity 'species' created.'
Table name 'STRDQRS' based on entity 'stored_queries' created.'
Table name 'SBPLTYPS' based on entity 'subplot_types' created.'
Table name 'PLTS' based on entity 'plots' created.'
Table name 'TRS' based on entity 'trees' created.'
Table name 'RSTRTYPRS' based on entity 'raster_type_areas' created.'

..blah, blah, blah...


With that little success... I'm off to the races!

A million thank yous!
Post by Evertjan.
Post by Evertjan.
var line = 'ADDRESS'
result = line.replace(/(.)\1/g,'$1')
document.write(result)
// ADRES
var line = 'ADdreesS'
result = line.replace(/(.)\1/g,'$1')
document.write(result)
// ADdresS
var line = 'ADdreesS'
result = line.replace(/(.)\1/ig,'$1')
document.write(result)
// ADres
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Loading...