Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex format? #81

Open
mushroomgenie opened this issue Feb 12, 2021 · 3 comments
Open

Regex format? #81

mushroomgenie opened this issue Feb 12, 2021 · 3 comments

Comments

@mushroomgenie
Copy link

mushroomgenie commented Feb 12, 2021

Is there any particular format in which we must write the regex expression? Because whenever I put bodyRegex, I get an empty array as response.

@rajanverma-me
Copy link

any update on this one? facing the same issue

@ALIAHSANRST
Copy link

same issue

@ALIAHSANRST
Copy link

ALIAHSANRST commented Jun 23, 2023

Hi i done some research and found out javaScript has Regular Expressions Which are basically if this Regex format is not working for you.
I have made a custom fucntion use Regular Expressions
I needed Regex to get sms which contains city , area and description change according to your needs

`const LocalSms = () => {
const [SmsCount, setSmsCount] = useState();
const [SmsBody, setSmsBody] = useState([]);

const [sms, setSms] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetch = async () => {
await requestSmsPermission();
read();
};
fetch();
}, []);

useFocusEffect(
React.useCallback(() => {
const fetch = async () => {
await requestSmsPermission();
read();
};
fetch();
return () => fetch();
}, [read]),
);

async function requestSmsPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_SMS,
{
title: 'SMS Permission',
message:
'This app needs access to your SMS messages to function properly.',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('SMS permission granted');
} else {
console.log('SMS permission denied');
}
} catch (err) {
console.warn(err);
}
}

const filter = {
box: 'inbox',
maxCount: 10,
};

const read = () => {
console.log('reading for read()');
SmsAndroid.list(
JSON.stringify(filter),
fail => console.log('Failed with error:', fail),
(count, smsList) => {
const parsedData = JSON.parse(smsList);
console.log('parsedData', parsedData);
validate(parsedData);
setSmsCount(count);
setLoading(false);
},
);
};

function validate(body) {
const regex = new RegExp('(city)|(area)|(description)');
const tempSms = [];
body.forEach(bodyData => {
if (regex.test(bodyData.body)) {
console.log('bodyData.body=', bodyData.body);
tempSms.push(bodyData.body);
}
setSmsBody(tempSms);
});
}

return (

{!loading ? (
<FlatList
showsVerticalScrollIndicator
style={styles.list}
data={SmsBody}
renderItem={({item, index}) => {
return (

{item}

);
}}
/>
) : (

<ActivityIndicator size={200} color={'#116A7B'} />
Fetching Sms

)}

);
};`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants