Составление регулярного выражения
Доброго времени суток. Помогите, пожалуйста, составить регулярное выражение, никак не получается :( Нужно разбить текст на массив, начиная от слова "Shape" и заканчивая двумя треугольными скобками. Должен получиться массив с 2-мя элементами.
<textarea id="text" style="display:block;width:400px; height:50px" name="" cols="" rows="">
Shape{
appearance Appearance{
maturial DEF Material #mat
Material{diffuseColor 1.0 1.0 1.0}
texture ImageTexture{url "txt4.tga" }}
geometry IndexedFaceSet{
creaseAngle 3.14
coord DEF sea08 Coordinate{
point[0 0 0]
}
coordIndex[
2,1,0,-1,2,0,3]
texCoord TextureCoordinate{
point[]
}
texCoordIndex[
2,1,0,-1,2,0,3,-1,2,3,4,]
}
}
Shape{
appearance Appearance{
material DEF Material - Default
Material{diffuseColor 1.0 1.0 1.0}
texture ImageTexture{url "dent5.tga" }}
geometry IndexedFaceSet{
creaseAngle 3.14
coord DEF sea08 Coordinate{
point[0 0 0]
}
coordIndex[
2,1,0,-1texCoord TextureCoordinate{
point[0 0]
}
texCoordIndex[
2,1,0,-1,2,0,3]
}
}
</textarea>
<input type="button" value="RegExp" onclick="RegExp_01()">
<script>
function RegExp_01(){
var raw_data = document.getElementById('text').value; //читаем текст из поля
var reg_exp = / /img;//регулярка
var data_array = raw_data.match(reg_exp);
console.log(JSON.stringify(data_array));
}
</script>
|
фонарик,
<textarea id="text" style="display:block;width:400px; height:50px" name="" cols="" rows="">
Shape{
appearance Appearance{
maturial DEF Material #mat
Material{diffuseColor 1.0 1.0 1.0}
texture ImageTexture{url "txt4.tga" }}
geometry IndexedFaceSet{
creaseAngle 3.14
coord DEF sea08 Coordinate{
point[0 0 0]
}
coordIndex[
2,1,0,-1,2,0,3]
texCoord TextureCoordinate{
point[]
}
texCoordIndex[
2,1,0,-1,2,0,3,-1,2,3,4,]
}
}
Shape{
appearance Appearance{
material DEF Material - Default
Material{diffuseColor 1.0 1.0 1.0}
texture ImageTexture{url "dent5.tga" }}
geometry IndexedFaceSet{
creaseAngle 3.14
coord DEF sea08 Coordinate{
point[0 0 0]
}
coordIndex[
2,1,0,-1texCoord TextureCoordinate{
point[0 0]
}
texCoordIndex[
2,1,0,-1,2,0,3]
}
}
</textarea>
<input type="button" value="RegExp" onclick="RegExp_01()">
<script>
function RegExp_01(){
var raw_data = document.getElementById('text').value; //читаем текст из поля
var data_array = raw_data.split('Shape').slice(1);
alert(JSON.stringify(data_array));
}
</script>
Вариант без regexp. |
Цитата:
Может еще кто вдогонку знает, можно ли в регулярке при поиске символов исключить определенный последовательный набор, слово определенное, короче говоря? Например, ищем кусок текста [\s\S]+ Как искать текст, но только до слова, например "text"? Используя конструкцию исключения [^text] исключается не слово, а только набор символов :( |
фонарик,
Цитата:
|
Цитата:
Все, составил регулярное выражение. Спасибо всем, кто пытался помочь :) |
| Часовой пояс GMT +3, время: 01:02. |